Search in sources :

Example 11 with InsertResult

use of org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleLegacyMessage.

private void handleLegacyMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(envelope);
        if (insertResult.isPresent()) {
            smsDatabase.markAsLegacyVersion(insertResult.get().getMessageId());
            MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsLegacyVersion(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase)

Example 12 with InsertResult

use of org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult 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 13 with InsertResult

use of org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult in project Signal-Android by WhisperSystems.

the class DirectoryHelper method notifyNewUsers.

private static void notifyNewUsers(@NonNull Context context, @Nullable MasterSecret masterSecret, @NonNull List<String> newUsers) {
    if (!TextSecurePreferences.isNewContactsNotificationEnabled(context))
        return;
    for (String newUser : newUsers) {
        if (!SessionUtil.hasSession(context, masterSecret, newUser) && !Util.isOwnNumber(context, newUser)) {
            IncomingJoinedMessage message = new IncomingJoinedMessage(newUser);
            Optional<InsertResult> insertResult = DatabaseFactory.getSmsDatabase(context).insertMessageInbox(message);
            if (insertResult.isPresent()) {
                int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                if (hour >= 9 && hour < 23) {
                    MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId(), true);
                } else {
                    MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId(), false);
                }
            }
        }
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) IncomingJoinedMessage(org.thoughtcrime.securesms.sms.IncomingJoinedMessage)

Aggregations

InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)13 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)9 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)6 Recipients (org.thoughtcrime.securesms.recipients.Recipients)4 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)3 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)2 IncomingMediaMessage (org.thoughtcrime.securesms.mms.IncomingMediaMessage)2 Uri (android.net.Uri)1 Nullable (android.support.annotation.Nullable)1 ByteString (com.google.protobuf.ByteString)1 LinkedList (java.util.LinkedList)1 Attachment (org.thoughtcrime.securesms.attachments.Attachment)1 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)1 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)1 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)1 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)1 AvatarDownloadJob (org.thoughtcrime.securesms.jobs.AvatarDownloadJob)1 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)1 SingleUseBlobProvider (org.thoughtcrime.securesms.providers.SingleUseBlobProvider)1 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)1