Search in sources :

Example 1 with AvatarDownloadJob

use of org.thoughtcrime.securesms.jobs.AvatarDownloadJob in project Signal-Android by WhisperSystems.

the class GroupMessageProcessor method storeMessage.

@Nullable
private static Long storeMessage(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, @NonNull GroupContext storage, boolean outgoing) {
    if (group.getAvatar().isPresent()) {
        ApplicationContext.getInstance(context).getJobManager().add(new AvatarDownloadJob(context, group.getGroupId()));
    }
    try {
        if (outgoing) {
            MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
            Recipients recipients = RecipientFactory.getRecipientsFromString(context, GroupUtil.getEncodedId(group.getGroupId()), false);
            OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(recipients, storage, null, envelope.getTimestamp(), 0);
            long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
            long messageId = mmsDatabase.insertMessageOutbox(masterSecret, outgoingMessage, threadId, false);
            mmsDatabase.markAsSent(messageId, true);
            return threadId;
        } else {
            EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
            String body = Base64.encodeBytes(storage.toByteArray());
            IncomingTextMessage incoming = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), envelope.getTimestamp(), body, Optional.of(group), 0);
            IncomingGroupMessage groupMessage = new IncomingGroupMessage(incoming, storage, body);
            Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(masterSecret, groupMessage);
            if (insertResult.isPresent()) {
                MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
                return insertResult.get().getThreadId();
            } else {
                return null;
            }
        }
    } catch (MmsException e) {
        Log.w(TAG, e);
    }
    return null;
}
Also used : IncomingGroupMessage(org.thoughtcrime.securesms.sms.IncomingGroupMessage) InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) MmsException(ws.com.google.android.mms.MmsException) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) AvatarDownloadJob(org.thoughtcrime.securesms.jobs.AvatarDownloadJob) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) ByteString(com.google.protobuf.ByteString) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) Nullable(android.support.annotation.Nullable)

Example 2 with AvatarDownloadJob

use of org.thoughtcrime.securesms.jobs.AvatarDownloadJob in project Signal-Android by signalapp.

the class GroupMessageProcessor method storeMessage.

@Nullable
private static Long storeMessage(@NonNull Context context, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, @NonNull GroupContext storage, boolean outgoing) {
    if (group.getAvatar().isPresent()) {
        ApplicationContext.getInstance(context).getJobManager().add(new AvatarDownloadJob(context, group.getGroupId()));
    }
    try {
        if (outgoing) {
            MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
            Address addres = Address.fromExternal(context, GroupUtil.getEncodedId(group.getGroupId(), false));
            Recipient recipient = Recipient.from(context, addres, false);
            OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(recipient, storage, null, envelope.getTimestamp(), 0);
            long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
            long messageId = mmsDatabase.insertMessageOutbox(outgoingMessage, threadId, false, null);
            mmsDatabase.markAsSent(messageId, true);
            return threadId;
        } else {
            SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
            String body = Base64.encodeBytes(storage.toByteArray());
            IncomingTextMessage incoming = new IncomingTextMessage(Address.fromExternal(context, envelope.getSource()), envelope.getSourceDevice(), envelope.getTimestamp(), body, Optional.of(group), 0);
            IncomingGroupMessage groupMessage = new IncomingGroupMessage(incoming, storage, body);
            Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(groupMessage);
            if (insertResult.isPresent()) {
                MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
                return insertResult.get().getThreadId();
            } else {
                return null;
            }
        }
    } catch (MmsException e) {
        Log.w(TAG, e);
    }
    return null;
}
Also used : IncomingGroupMessage(org.thoughtcrime.securesms.sms.IncomingGroupMessage) InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) Address(org.thoughtcrime.securesms.database.Address) AvatarDownloadJob(org.thoughtcrime.securesms.jobs.AvatarDownloadJob) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) MmsException(org.thoughtcrime.securesms.mms.MmsException) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)2 ByteString (com.google.protobuf.ByteString)2 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)2 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)2 AvatarDownloadJob (org.thoughtcrime.securesms.jobs.AvatarDownloadJob)2 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)2 IncomingGroupMessage (org.thoughtcrime.securesms.sms.IncomingGroupMessage)2 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)2 Address (org.thoughtcrime.securesms.database.Address)1 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)1 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)1 MmsException (org.thoughtcrime.securesms.mms.MmsException)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1 MmsException (ws.com.google.android.mms.MmsException)1