Search in sources :

Example 1 with OutgoingMediaMessage

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

the class PushMediaSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws RetryLaterException, MmsException, NoSuchMessageException, UndeliverableMessageException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        deliver(masterSecret, message);
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message.getAttachments());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException ifae) {
        Log.w(TAG, ifae);
        database.markAsPendingInsecureSmsFallback(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
    } catch (UntrustedIdentityException uie) {
        Log.w(TAG, uie);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, uie.getE164Number(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        database.addMismatchedIdentity(messageId, recipientId, uie.getIdentityKey());
        database.markAsSentFailed(messageId);
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 2 with OutgoingMediaMessage

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

the class AndroidAutoReplyReceiver method onReceive.

@Override
protected void onReceive(final Context context, Intent intent, @Nullable final MasterSecret masterSecret) {
    if (!REPLY_ACTION.equals(intent.getAction()))
        return;
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null)
        return;
    final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
    final long threadId = intent.getLongExtra(THREAD_ID_EXTRA, -1);
    final CharSequence responseText = getMessageText(intent);
    final Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
    if (responseText != null) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                long replyThreadId;
                Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(recipientIds);
                int subscriptionId = preferences.isPresent() ? preferences.get().getDefaultSubscriptionId().or(-1) : -1;
                long expiresIn = preferences.isPresent() ? preferences.get().getExpireMessages() * 1000 : 0;
                if (recipients.isGroupRecipient()) {
                    Log.i("AndroidAutoReplyReceiver", "GroupRecipient, Sending media message");
                    OutgoingMediaMessage reply = new OutgoingMediaMessage(recipients, responseText.toString(), new LinkedList<Attachment>(), System.currentTimeMillis(), subscriptionId, expiresIn, 0);
                    replyThreadId = MessageSender.send(context, masterSecret, reply, threadId, false);
                } else {
                    Log.i("AndroidAutoReplyReceiver", "Sending regular message ");
                    OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString(), expiresIn, subscriptionId);
                    replyThreadId = MessageSender.send(context, masterSecret, reply, threadId, false);
                }
                List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(replyThreadId, true);
                MessageNotifier.updateNotification(context, masterSecret);
                MarkReadReceiver.process(context, messageIds);
                return null;
            }
        }.execute();
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) Optional(org.whispersystems.libsignal.util.guava.Optional) Bundle(android.os.Bundle) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 3 with OutgoingMediaMessage

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

the class RemoteReplyReceiver method onReceive.

@Override
protected void onReceive(final Context context, Intent intent, @Nullable final MasterSecret masterSecret) {
    if (!REPLY_ACTION.equals(intent.getAction()))
        return;
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null)
        return;
    final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
    final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_REMOTE_REPLY);
    if (masterSecret != null && responseText != null) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                long threadId;
                Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(recipientIds);
                int subscriptionId = preferences.isPresent() ? preferences.get().getDefaultSubscriptionId().or(-1) : -1;
                long expiresIn = preferences.isPresent() ? preferences.get().getExpireMessages() * 1000 : 0;
                Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
                if (recipients.isGroupRecipient()) {
                    OutgoingMediaMessage reply = new OutgoingMediaMessage(recipients, responseText.toString(), new LinkedList<Attachment>(), System.currentTimeMillis(), subscriptionId, expiresIn, 0);
                    threadId = MessageSender.send(context, masterSecret, reply, -1, false);
                } else {
                    OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString(), expiresIn, subscriptionId);
                    threadId = MessageSender.send(context, masterSecret, reply, -1, false);
                }
                List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
                MessageNotifier.updateNotification(context, masterSecret);
                MarkReadReceiver.process(context, messageIds);
                return null;
            }
        }.execute();
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) Optional(org.whispersystems.libsignal.util.guava.Optional) Recipients(org.thoughtcrime.securesms.recipients.Recipients) Bundle(android.os.Bundle) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 4 with OutgoingMediaMessage

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

the class QuickResponseService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent, @Nullable MasterSecret masterSecret) {
    if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
        Log.w(TAG, "Received unknown intent: " + intent.getAction());
        return;
    }
    if (masterSecret == null) {
        Log.w(TAG, "Got quick response request when locked...");
        Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_Signal_is_locked, Toast.LENGTH_LONG).show();
        return;
    }
    try {
        Rfc5724Uri uri = new Rfc5724Uri(intent.getDataString());
        String content = intent.getStringExtra(Intent.EXTRA_TEXT);
        String numbers = uri.getPath();
        if (numbers.contains("%")) {
            numbers = URLDecoder.decode(numbers);
        }
        Recipients recipients = RecipientFactory.getRecipientsFromString(this, numbers, false);
        Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(this).getRecipientsPreferences(recipients.getIds());
        int subscriptionId = preferences.isPresent() ? preferences.get().getDefaultSubscriptionId().or(-1) : -1;
        long expiresIn = preferences.isPresent() ? preferences.get().getExpireMessages() * 1000 : 0;
        if (!TextUtils.isEmpty(content)) {
            if (recipients.isSingleRecipient()) {
                MessageSender.send(this, masterSecret, new OutgoingTextMessage(recipients, content, expiresIn, subscriptionId), -1, false);
            } else {
                MessageSender.send(this, masterSecret, new OutgoingMediaMessage(recipients, new SlideDeck(), content, System.currentTimeMillis(), subscriptionId, expiresIn, ThreadDatabase.DistributionTypes.DEFAULT), -1, false);
            }
        }
    } catch (URISyntaxException e) {
        Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show();
        Log.w(TAG, e);
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) Rfc5724Uri(org.thoughtcrime.securesms.util.Rfc5724Uri) Recipients(org.thoughtcrime.securesms.recipients.Recipients) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) RecipientsPreferences(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) URISyntaxException(java.net.URISyntaxException)

Example 5 with OutgoingMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingMediaMessage 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)

Aggregations

OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)10 Recipients (org.thoughtcrime.securesms.recipients.Recipients)6 LinkedList (java.util.LinkedList)5 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)4 List (java.util.List)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 OutgoingSecureMediaMessage (org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)3 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)3 Bundle (android.os.Bundle)2 IOException (java.io.IOException)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 MmsNotificationAttachment (org.thoughtcrime.securesms.attachments.MmsNotificationAttachment)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 Optional (org.whispersystems.libsignal.util.guava.Optional)2 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2 MmsException (ws.com.google.android.mms.MmsException)2 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 Cursor (android.database.Cursor)1