Search in sources :

Example 46 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleSynchronizeSentMediaMessage.

private long handleSynchronizeSentMediaMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SentTranscriptMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    Recipients recipients = getSyncMessageDestination(message);
    OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(recipients, message.getMessage().getBody().orNull(), PointerAttachment.forPointers(masterSecret, message.getMessage().getAttachments()), message.getTimestamp(), -1, message.getMessage().getExpiresInSeconds() * 1000, ThreadDatabase.DistributionTypes.DEFAULT);
    mediaMessage = new OutgoingSecureMediaMessage(mediaMessage);
    if (recipients.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
        handleSynchronizeSentExpirationUpdate(masterSecret, message, Optional.<Long>absent());
    }
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
    long messageId = database.insertMessageOutbox(masterSecret, mediaMessage, threadId, false);
    database.markAsSent(messageId, true);
    for (DatabaseAttachment attachment : DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(messageId)) {
        ApplicationContext.getInstance(context).getJobManager().add(new AttachmentDownloadJob(context, messageId, attachment.getAttachmentId()));
    }
    if (smsMessageId.isPresent()) {
        DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
    }
    if (message.getMessage().getExpiresInSeconds() > 0) {
        database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
        ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, true, message.getExpirationStartTimestamp(), message.getMessage().getExpiresInSeconds());
    }
    return threadId;
}
Also used : OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 47 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleSynchronizeSentEndSessionMessage.

private long handleSynchronizeSentEndSessionMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SentTranscriptMessage message, @NonNull Optional<Long> smsMessageId) {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    Recipients recipients = getSyncMessageDestination(message);
    OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipients, "", -1);
    OutgoingEndSessionMessage outgoingEndSessionMessage = new OutgoingEndSessionMessage(outgoingTextMessage);
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
    if (recipients.isSingleRecipient() && !recipients.isGroupRecipient()) {
        SessionStore sessionStore = new TextSecureSessionStore(context);
        sessionStore.deleteAllSessions(recipients.getPrimaryRecipient().getNumber());
        SecurityEvent.broadcastSecurityUpdateEvent(context);
        long messageId = database.insertMessageOutbox(masterSecret, threadId, outgoingEndSessionMessage, false, message.getTimestamp());
        database.markAsSent(messageId, true);
    }
    if (smsMessageId.isPresent()) {
        database.deleteMessage(smsMessageId.get());
    }
    return threadId;
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) OutgoingEndSessionMessage(org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) Recipients(org.thoughtcrime.securesms.recipients.Recipients) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase)

Example 48 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleExpirationUpdate.

private void handleExpirationUpdate(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    String localNumber = TextSecurePreferences.getLocalNumber(context);
    Recipients recipients = getMessageDestination(envelope, message);
    IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(), localNumber, message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000, true, Optional.fromNullable(envelope.getRelay()), Optional.<String>absent(), message.getGroupInfo(), Optional.<List<SignalServiceAttachment>>absent());
    database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);
    DatabaseFactory.getRecipientPreferenceDatabase(context).setExpireMessages(recipients, message.getExpiresInSeconds());
    if (smsMessageId.isPresent()) {
        DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
    }
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Recipients(org.thoughtcrime.securesms.recipients.Recipients) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 49 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleSynchronizeSentTextMessage.

private long handleSynchronizeSentTextMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SentTranscriptMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    Recipients recipients = getSyncMessageDestination(message);
    String body = message.getMessage().getBody().or("");
    long expiresInMillis = message.getMessage().getExpiresInSeconds() * 1000;
    OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipients, body, expiresInMillis, -1);
    if (recipients.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
        handleSynchronizeSentExpirationUpdate(masterSecret, message, Optional.<Long>absent());
    }
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
    long messageId = database.insertMessageOutbox(masterSecret, threadId, outgoingTextMessage, false, message.getTimestamp());
    database.markAsSent(messageId, true);
    if (smsMessageId.isPresent()) {
        database.deleteMessage(smsMessageId.get());
    }
    if (expiresInMillis > 0) {
        database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
        ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, false, message.getExpirationStartTimestamp(), expiresInMillis);
    }
    return threadId;
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase)

Example 50 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class DirectShareService method onGetChooserTargets.

@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    List<ChooserTarget> results = new LinkedList<>();
    MasterSecret masterSecret = KeyCachingService.getMasterSecret(this);
    if (masterSecret == null) {
        return results;
    }
    ComponentName componentName = new ComponentName(this, ShareActivity.class);
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(this);
    Cursor cursor = threadDatabase.getDirectShareList();
    try {
        ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor, new MasterCipher(masterSecret));
        ThreadRecord record;
        while ((record = reader.getNext()) != null && results.size() < 10) {
            Recipients recipients = RecipientFactory.getRecipientsForIds(this, record.getRecipients().getIds(), false);
            String name = recipients.toShortString();
            Drawable drawable = recipients.getContactPhoto().asDrawable(this, recipients.getColor().toConversationColor(this));
            Bitmap avatar = BitmapUtil.createFromDrawable(drawable, 500, 500);
            Bundle bundle = new Bundle();
            bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getThreadId());
            bundle.putLongArray(ShareActivity.EXTRA_RECIPIENT_IDS, recipients.getIds());
            bundle.putInt(ShareActivity.EXTRA_DISTRIBUTION_TYPE, record.getDistributionType());
            results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
        }
        return results;
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) Recipients(org.thoughtcrime.securesms.recipients.Recipients) Bundle(android.os.Bundle) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Drawable(android.graphics.drawable.Drawable) MasterCipher(org.thoughtcrime.securesms.crypto.MasterCipher) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) Bitmap(android.graphics.Bitmap) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName)

Aggregations

Recipients (org.thoughtcrime.securesms.recipients.Recipients)52 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)7 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)7 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)6 LinkedList (java.util.LinkedList)5 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)5 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)5 Intent (android.content.Intent)4 Bundle (android.os.Bundle)4 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)4 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)4 MmsException (ws.com.google.android.mms.MmsException)4 Cursor (android.database.Cursor)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 NonNull (android.support.annotation.NonNull)3 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)3 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)3