Search in sources :

Example 16 with EncryptingSmsDatabase

use of org.thoughtcrime.securesms.database.EncryptingSmsDatabase 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 17 with EncryptingSmsDatabase

use of org.thoughtcrime.securesms.database.EncryptingSmsDatabase 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 18 with EncryptingSmsDatabase

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

the class MessageSender method send.

public static long send(final Context context, final MasterSecret masterSecret, final OutgoingTextMessage message, final long threadId, final boolean forceSms) {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    Recipients recipients = message.getRecipients();
    boolean keyExchange = message.isKeyExchange();
    long allocatedThreadId;
    if (threadId == -1) {
        allocatedThreadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
    } else {
        allocatedThreadId = threadId;
    }
    long messageId = database.insertMessageOutbox(new MasterSecretUnion(masterSecret), allocatedThreadId, message, forceSms, System.currentTimeMillis());
    sendTextMessage(context, recipients, forceSms, keyExchange, messageId, message.getExpiresIn());
    return allocatedThreadId;
}
Also used : MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) Recipients(org.thoughtcrime.securesms.recipients.Recipients) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase)

Example 19 with EncryptingSmsDatabase

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

the class MessageSender method sendTextSelf.

private static void sendTextSelf(Context context, long messageId, long expiresIn) {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    database.markAsSent(messageId, true);
    Pair<Long, Long> messageAndThreadId = database.copyMessageInbox(messageId);
    database.markAsPush(messageAndThreadId.first);
    if (expiresIn > 0) {
        ExpiringMessageManager expiringMessageManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
        database.markExpireStarted(messageId);
        expiringMessageManager.scheduleDeletion(messageId, false, expiresIn);
    }
}
Also used : EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager)

Aggregations

EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)19 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)9 Recipients (org.thoughtcrime.securesms.recipients.Recipients)7 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)6 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)4 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)3 Nullable (android.support.annotation.Nullable)2 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)2 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)2 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)2 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)2 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)2 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 SessionStore (org.whispersystems.libsignal.state.SessionStore)2 ByteString (com.google.protobuf.ByteString)1 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)1 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)1 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)1 AvatarDownloadJob (org.thoughtcrime.securesms.jobs.AvatarDownloadJob)1