Search in sources :

Example 1 with IncomingEncryptedMessage

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

the class PushDecryptJob method insertPlaceholder.

private Optional<InsertResult> insertPlaceholder(@NonNull SignalServiceEnvelope envelope) {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), envelope.getTimestamp(), "", Optional.<SignalServiceGroup>absent(), 0);
    textMessage = new IncomingEncryptedMessage(textMessage, "");
    return database.insertMessageInbox(textMessage);
}
Also used : IncomingEncryptedMessage(org.thoughtcrime.securesms.sms.IncomingEncryptedMessage) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 2 with IncomingEncryptedMessage

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

the class PushDecryptJob method handleTextMessage.

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

Aggregations

EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)2 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)2 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)2 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1