Search in sources :

Example 16 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleSynchronizeSentExpirationUpdate.

private long handleSynchronizeSentExpirationUpdate(@NonNull MasterSecretUnion masterSecret, @NonNull SentTranscriptMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    Recipients recipients = getSyncMessageDestination(message);
    OutgoingExpirationUpdateMessage expirationUpdateMessage = new OutgoingExpirationUpdateMessage(recipients, message.getTimestamp(), message.getMessage().getExpiresInSeconds() * 1000);
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
    long messageId = database.insertMessageOutbox(masterSecret, expirationUpdateMessage, threadId, false);
    database.markAsSent(messageId, true);
    DatabaseFactory.getRecipientPreferenceDatabase(context).setExpireMessages(recipients, message.getMessage().getExpiresInSeconds());
    if (smsMessageId.isPresent()) {
        DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
    }
    return threadId;
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 17 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleUntrustedIdentityMessage.

private void handleUntrustedIdentityMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    try {
        EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        byte[] serialized = envelope.hasLegacyMessage() ? envelope.getLegacyMessage() : envelope.getContent();
        PreKeySignalMessage whisperMessage = new PreKeySignalMessage(serialized);
        IdentityKey identityKey = whisperMessage.getIdentityKey();
        String encoded = Base64.encodeBytes(serialized);
        IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), envelope.getTimestamp(), encoded, Optional.<SignalServiceGroup>absent(), 0);
        if (!smsMessageId.isPresent()) {
            IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded, envelope.hasLegacyMessage());
            Optional<InsertResult> insertResult = database.insertMessageInbox(masterSecret, bundleMessage);
            if (insertResult.isPresent()) {
                database.setMismatchedIdentity(insertResult.get().getMessageId(), recipientId, identityKey);
                MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
            }
        } else {
            database.updateMessageBody(masterSecret, smsMessageId.get(), encoded);
            database.markAsPreKeyBundle(smsMessageId.get());
            database.setMismatchedIdentity(smsMessageId.get(), recipientId, identityKey);
        }
    } catch (InvalidMessageException | InvalidVersionException e) {
        throw new AssertionError(e);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) IdentityKey(org.whispersystems.libsignal.IdentityKey) Recipients(org.thoughtcrime.securesms.recipients.Recipients) InvalidVersionException(org.whispersystems.libsignal.InvalidVersionException) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingPreKeyBundleMessage(org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage) PreKeySignalMessage(org.whispersystems.libsignal.protocol.PreKeySignalMessage) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 18 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PushTextSendJob method onCanceled.

@Override
public void onCanceled() {
    DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId);
    long threadId = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageId);
    Recipients recipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
    if (threadId != -1 && recipients != null) {
        MessageNotifier.notifyMessageDeliveryFailed(context, recipients, threadId);
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients)

Example 19 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PushTextSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws NoSuchMessageException, RetryLaterException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(masterSecret, messageId);
    try {
        Log.w(TAG, "Sending message: " + messageId);
        deliver(record);
        database.markAsSent(messageId, true);
        if (record.getExpiresIn() > 0) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException e) {
        Log.w(TAG, e);
        database.markAsPendingInsecureSmsFallback(record.getId());
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, e);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, e.getE164Number(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        database.addMismatchedIdentity(record.getId(), recipientId, e.getIdentityKey());
        database.markAsSentFailed(record.getId());
        database.markAsPush(record.getId());
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)

Example 20 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class IdentityUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws Exception {
    Recipient recipient = RecipientFactory.getRecipientForId(context, recipientId, true);
    Recipients recipients = RecipientFactory.getRecipientsFor(context, recipient, true);
    String number = recipient.getNumber();
    long time = System.currentTimeMillis();
    SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    GroupDatabase.Reader reader = groupDatabase.getGroups();
    GroupDatabase.GroupRecord groupRecord;
    while ((groupRecord = reader.getNext()) != null) {
        if (groupRecord.getMembers().contains(number) && groupRecord.isActive()) {
            SignalServiceGroup group = new SignalServiceGroup(groupRecord.getId());
            IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.of(group), 0);
            IncomingIdentityUpdateMessage groupUpdate = new IncomingIdentityUpdateMessage(incoming);
            smsDatabase.insertMessageInbox(groupUpdate);
        }
    }
    if (threadDatabase.getThreadIdIfExistsFor(recipients) != -1) {
        IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.<SignalServiceGroup>absent(), 0);
        IncomingIdentityUpdateMessage individualUpdate = new IncomingIdentityUpdateMessage(incoming);
        smsDatabase.insertMessageInbox(individualUpdate);
    }
}
Also used : IncomingIdentityUpdateMessage(org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

Aggregations

Recipients (org.thoughtcrime.securesms.recipients.Recipients)52 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)7 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)7 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)6 LinkedList (java.util.LinkedList)5 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)5 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)5 Intent (android.content.Intent)4 Bundle (android.os.Bundle)4 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)4 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)4 MmsException (ws.com.google.android.mms.MmsException)4 Cursor (android.database.Cursor)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 NonNull (android.support.annotation.NonNull)3 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)3 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)3