Search in sources :

Example 1 with OutgoingSecureMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage in project Signal-Android by WhisperSystems.

the class ConversationActivity method sendMediaMessage.

private ListenableFuture<Void> sendMediaMessage(final boolean forceSms, String body, SlideDeck slideDeck, final long expiresIn, final int subscriptionId) throws InvalidMessageException {
    final SettableFuture<Void> future = new SettableFuture<>();
    final Context context = getApplicationContext();
    OutgoingMediaMessage outgoingMessage = new OutgoingMediaMessage(recipients, slideDeck, body, System.currentTimeMillis(), subscriptionId, expiresIn, distributionType);
    if (isSecureText && !forceSms) {
        outgoingMessage = new OutgoingSecureMediaMessage(outgoingMessage);
    }
    attachmentManager.clear();
    composeText.setText("");
    new AsyncTask<OutgoingMediaMessage, Void, Long>() {

        @Override
        protected Long doInBackground(OutgoingMediaMessage... messages) {
            return MessageSender.send(context, masterSecret, messages[0], threadId, forceSms);
        }

        @Override
        protected void onPostExecute(Long result) {
            sendComplete(result);
            future.set(null);
        }
    }.execute(outgoingMessage);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Context(android.content.Context) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage)

Example 2 with OutgoingSecureMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage 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 3 with OutgoingSecureMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage in project Signal-Android by WhisperSystems.

the class MmsDatabase method getOutgoingMessage.

public OutgoingMediaMessage getOutgoingMessage(MasterSecret masterSecret, long messageId) throws MmsException, NoSuchMessageException {
    MmsAddressDatabase addr = DatabaseFactory.getMmsAddressDatabase(context);
    AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
    Cursor cursor = null;
    try {
        cursor = rawQuery(RAW_ID_WHERE, new String[] { String.valueOf(messageId) });
        if (cursor != null && cursor.moveToNext()) {
            long outboxType = cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX));
            String messageText = cursor.getString(cursor.getColumnIndexOrThrow(BODY));
            long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(NORMALIZED_DATE_SENT));
            int subscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(SUBSCRIPTION_ID));
            long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(EXPIRES_IN));
            List<Attachment> attachments = new LinkedList<Attachment>(attachmentDatabase.getAttachmentsForMessage(messageId));
            MmsAddresses addresses = addr.getAddressesForId(messageId);
            List<String> destinations = new LinkedList<>();
            String body = getDecryptedBody(masterSecret, messageText, outboxType);
            destinations.addAll(addresses.getBcc());
            destinations.addAll(addresses.getCc());
            destinations.addAll(addresses.getTo());
            Recipients recipients = RecipientFactory.getRecipientsFromStrings(context, destinations, false);
            if (body != null && (Types.isGroupQuit(outboxType) || Types.isGroupUpdate(outboxType))) {
                return new OutgoingGroupMediaMessage(recipients, body, attachments, timestamp, 0);
            } else if (Types.isExpirationTimerUpdate(outboxType)) {
                return new OutgoingExpirationUpdateMessage(recipients, timestamp, expiresIn);
            }
            OutgoingMediaMessage message = new OutgoingMediaMessage(recipients, body, attachments, timestamp, subscriptionId, expiresIn, !addresses.getBcc().isEmpty() ? ThreadDatabase.DistributionTypes.BROADCAST : ThreadDatabase.DistributionTypes.DEFAULT);
            if (Types.isSecureType(outboxType)) {
                return new OutgoingSecureMediaMessage(message);
            }
            return message;
        }
        throw new NoSuchMessageException("No record found for id: " + messageId);
    } catch (IOException e) {
        throw new MmsException(e);
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) Attachment(org.thoughtcrime.securesms.attachments.Attachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MmsNotificationAttachment(org.thoughtcrime.securesms.attachments.MmsNotificationAttachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) IOException(java.io.IOException) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) MmsException(ws.com.google.android.mms.MmsException) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage)

Aggregations

OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)3 OutgoingSecureMediaMessage (org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 Context (android.content.Context)1 Cursor (android.database.Cursor)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Attachment (org.thoughtcrime.securesms.attachments.Attachment)1 MmsNotificationAttachment (org.thoughtcrime.securesms.attachments.MmsNotificationAttachment)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 OutgoingExpirationUpdateMessage (org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage)1 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)1 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)1 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)1 MmsException (ws.com.google.android.mms.MmsException)1