Search in sources :

Example 6 with IncomingTextMessage

use of org.thoughtcrime.securesms.sms.IncomingTextMessage 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)

Example 7 with IncomingTextMessage

use of org.thoughtcrime.securesms.sms.IncomingTextMessage 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 8 with IncomingTextMessage

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

the class SmsReceiveJob method storeMessage.

private Optional<InsertResult> storeMessage(MasterSecretUnion masterSecret, IncomingTextMessage message) {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    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(masterSecret, message);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 9 with IncomingTextMessage

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

the class PushDecryptJob method handleEndSessionMessage.

private void handleEndSessionMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) {
    EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
    IncomingTextMessage incomingTextMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), message.getTimestamp(), "", Optional.<SignalServiceGroup>absent(), 0);
    Long threadId;
    if (!smsMessageId.isPresent()) {
        IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage);
        Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(masterSecret, incomingEndSessionMessage);
        if (insertResult.isPresent())
            threadId = insertResult.get().getThreadId();
        else
            threadId = null;
    } else {
        smsDatabase.markAsEndSession(smsMessageId.get());
        threadId = smsDatabase.getThreadIdForMessage(smsMessageId.get());
    }
    if (threadId != null) {
        SessionStore sessionStore = new TextSecureSessionStore(context);
        sessionStore.deleteAllSessions(envelope.getSource());
        SecurityEvent.broadcastSecurityUpdateEvent(context);
        MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) IncomingEndSessionMessage(org.thoughtcrime.securesms.sms.IncomingEndSessionMessage) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 10 with IncomingTextMessage

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

the class SmsReceiveJob method storeMessage.

private Optional<InsertResult> storeMessage(IncomingTextMessage message) throws MigrationPendingException {
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    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.MessagingDatabase.InsertResult) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

Aggregations

IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)14 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)11 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)7 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)6 Recipients (org.thoughtcrime.securesms.recipients.Recipients)4 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)4 Recipient (org.thoughtcrime.securesms.recipients.Recipient)3 Nullable (android.support.annotation.Nullable)2 ByteString (com.google.protobuf.ByteString)2 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)2 Address (org.thoughtcrime.securesms.database.Address)2 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)2 AvatarDownloadJob (org.thoughtcrime.securesms.jobs.AvatarDownloadJob)2 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)2 IncomingEndSessionMessage (org.thoughtcrime.securesms.sms.IncomingEndSessionMessage)2 IncomingGroupMessage (org.thoughtcrime.securesms.sms.IncomingGroupMessage)2 IncomingPreKeyBundleMessage (org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage)2 IdentityKey (org.whispersystems.libsignal.IdentityKey)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 InvalidVersionException (org.whispersystems.libsignal.InvalidVersionException)2