Search in sources :

Example 16 with IncomingTextMessage

use of org.thoughtcrime.securesms.sms.IncomingTextMessage in project Signal-Android by signalapp.

the class PushDecryptJob method handleTextMessage.

private void handleTextMessage(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    String body = message.getBody().isPresent() ? message.getBody().get() : "";
    Recipient recipient = getMessageDestination(envelope, message);
    if (message.getExpiresInSeconds() != recipient.getExpireMessages()) {
        handleExpirationUpdate(envelope, message, Optional.absent());
    }
    Long threadId;
    if (smsMessageId.isPresent() && !message.getGroupInfo().isPresent()) {
        threadId = database.updateBundleMessageBody(smsMessageId.get(), body).second;
    } else {
        IncomingTextMessage textMessage = new IncomingTextMessage(Address.fromExternal(context, envelope.getSource()), envelope.getSourceDevice(), message.getTimestamp(), body, message.getGroupInfo(), message.getExpiresInSeconds() * 1000L);
        textMessage = new IncomingEncryptedMessage(textMessage, body);
        Optional<InsertResult> insertResult = database.insertMessageInbox(textMessage);
        if (insertResult.isPresent())
            threadId = insertResult.get().getThreadId();
        else
            threadId = null;
        if (smsMessageId.isPresent())
            database.deleteMessage(smsMessageId.get());
    }
    if (threadId != null) {
        MessageNotifier.updateNotification(context, threadId);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) IncomingEncryptedMessage(org.thoughtcrime.securesms.sms.IncomingEncryptedMessage) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Example 17 with IncomingTextMessage

use of org.thoughtcrime.securesms.sms.IncomingTextMessage in project Signal-Android by signalapp.

the class PushDecryptJob method handleUntrustedIdentityMessage.

private void handleUntrustedIdentityMessage(@NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    try {
        SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
        Address sourceAddress = Address.fromExternal(context, envelope.getSource());
        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(sourceAddress, envelope.getSourceDevice(), envelope.getTimestamp(), encoded, Optional.absent(), 0);
        if (!smsMessageId.isPresent()) {
            IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded, envelope.hasLegacyMessage());
            Optional<InsertResult> insertResult = database.insertMessageInbox(bundleMessage);
            if (insertResult.isPresent()) {
                database.setMismatchedIdentity(insertResult.get().getMessageId(), sourceAddress, identityKey);
                MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
            }
        } else {
            database.updateMessageBody(smsMessageId.get(), encoded);
            database.markAsPreKeyBundle(smsMessageId.get());
            database.setMismatchedIdentity(smsMessageId.get(), sourceAddress, 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) Address(org.thoughtcrime.securesms.database.Address) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) InvalidVersionException(org.whispersystems.libsignal.InvalidVersionException) IncomingPreKeyBundleMessage(org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage) PreKeySignalMessage(org.whispersystems.libsignal.protocol.PreKeySignalMessage) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

Example 18 with IncomingTextMessage

use of org.thoughtcrime.securesms.sms.IncomingTextMessage in project Signal-Android by WhisperSystems.

the class SmsReceiveJob method assembleMessageFragments.

private Optional<IncomingTextMessage> assembleMessageFragments(@Nullable Object[] pdus, int subscriptionId) {
    if (pdus == null) {
        return Optional.absent();
    }
    List<IncomingTextMessage> messages = new LinkedList<>();
    for (Object pdu : pdus) {
        SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu);
        Recipient recipient = Recipient.external(context, message.getDisplayOriginatingAddress());
        messages.add(new IncomingTextMessage(recipient.getId(), message, subscriptionId));
    }
    if (messages.isEmpty()) {
        return Optional.absent();
    }
    return Optional.of(new IncomingTextMessage(messages));
}
Also used : SmsMessage(android.telephony.SmsMessage) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LinkedList(java.util.LinkedList)

Example 19 with IncomingTextMessage

use of org.thoughtcrime.securesms.sms.IncomingTextMessage in project Signal-Android by WhisperSystems.

the class SmsReceiveJob method storeMessage.

private Optional<InsertResult> storeMessage(IncomingTextMessage message) throws MigrationPendingException {
    MessageDatabase database = SignalDatabase.sms();
    database.ensureMigration();
    if (TextSecurePreferences.getNeedsSqlCipherMigration(context)) {
        throw new MigrationPendingException();
    }
    if (message.isSecureMessage()) {
        IncomingTextMessage placeholder = new IncomingTextMessage(message, "");
        Optional<InsertResult> insertResult = database.insertMessageInbox(placeholder);
        database.markAsLegacyVersion(insertResult.get().getMessageId());
        return insertResult;
    } else {
        return database.insertMessageInbox(message);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 20 with IncomingTextMessage

use of org.thoughtcrime.securesms.sms.IncomingTextMessage in project Signal-Android by WhisperSystems.

the class MessageContentProcessor method handleTextMessage.

@Nullable
private MessageId handleTextMessage(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId, @NonNull Optional<GroupId> groupId, @NonNull Recipient senderRecipient, @NonNull Recipient threadRecipient, long receivedTime) throws StorageFailedException {
    log(message.getTimestamp(), "Text message.");
    MessageDatabase database = SignalDatabase.sms();
    String body = message.getBody().isPresent() ? message.getBody().get() : "";
    if (message.getExpiresInSeconds() != threadRecipient.getExpiresInSeconds()) {
        handleExpirationUpdate(content, message, Optional.absent(), groupId, senderRecipient, threadRecipient, receivedTime);
    }
    Optional<InsertResult> insertResult;
    if (smsMessageId.isPresent() && !message.getGroupContext().isPresent()) {
        insertResult = Optional.of(database.updateBundleMessageBody(smsMessageId.get(), body));
    } else {
        notifyTypingStoppedFromIncomingMessage(senderRecipient, threadRecipient, content.getSenderDevice());
        IncomingTextMessage textMessage = new IncomingTextMessage(senderRecipient.getId(), content.getSenderDevice(), message.getTimestamp(), content.getServerReceivedTimestamp(), receivedTime, body, groupId, TimeUnit.SECONDS.toMillis(message.getExpiresInSeconds()), content.isNeedsReceipt(), content.getServerUuid());
        textMessage = new IncomingEncryptedMessage(textMessage, body);
        insertResult = database.insertMessageInbox(textMessage);
        if (smsMessageId.isPresent())
            database.deleteMessage(smsMessageId.get());
    }
    if (insertResult.isPresent()) {
        ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
        return new MessageId(insertResult.get().getMessageId(), false);
    } else {
        return null;
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) IncomingEncryptedMessage(org.thoughtcrime.securesms.sms.IncomingEncryptedMessage) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) MessageId(org.thoughtcrime.securesms.database.model.MessageId) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) Nullable(androidx.annotation.Nullable)

Aggregations

IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)22 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)10 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)7 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)7 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)6 InsertResult (org.thoughtcrime.securesms.database.MessageDatabase.InsertResult)6 Recipient (org.thoughtcrime.securesms.recipients.Recipient)6 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)6 Recipients (org.thoughtcrime.securesms.recipients.Recipients)4 Nullable (androidx.annotation.Nullable)3 ByteString (com.google.protobuf.ByteString)3 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)3 IncomingEndSessionMessage (org.thoughtcrime.securesms.sms.IncomingEndSessionMessage)3 Nullable (android.support.annotation.Nullable)2 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)2 Address (org.thoughtcrime.securesms.database.Address)2 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)2 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)2 MessageId (org.thoughtcrime.securesms.database.model.MessageId)2 AvatarDownloadJob (org.thoughtcrime.securesms.jobs.AvatarDownloadJob)2