Search in sources :

Example 1 with OutgoingTextMessage

use of org.thoughtcrime.securesms.sms.OutgoingTextMessage 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 2 with OutgoingTextMessage

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

use of org.thoughtcrime.securesms.sms.OutgoingTextMessage 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 4 with OutgoingTextMessage

use of org.thoughtcrime.securesms.sms.OutgoingTextMessage in project Signal-Android by WhisperSystems.

the class ConversationActivity method sendTextMessage.

private void sendTextMessage(final boolean forceSms, final long expiresIn, final int subscriptionId) throws InvalidMessageException {
    final Context context = getApplicationContext();
    OutgoingTextMessage message;
    if (isSecureText && !forceSms) {
        message = new OutgoingEncryptedMessage(recipients, getMessage(), expiresIn);
    } else {
        message = new OutgoingTextMessage(recipients, getMessage(), expiresIn, subscriptionId);
    }
    this.composeText.setText("");
    new AsyncTask<OutgoingTextMessage, Void, Long>() {

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

        @Override
        protected void onPostExecute(Long result) {
            sendComplete(result);
        }
    }.execute(message);
}
Also used : GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Context(android.content.Context) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) OutgoingEncryptedMessage(org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage)

Example 5 with OutgoingTextMessage

use of org.thoughtcrime.securesms.sms.OutgoingTextMessage in project Signal-Android by signalapp.

the class AndroidAutoReplyReceiver method onReceive.

@SuppressLint("StaticFieldLeak")
@Override
public void onReceive(final Context context, Intent intent) {
    if (!REPLY_ACTION.equals(intent.getAction()))
        return;
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null)
        return;
    final Address address = intent.getParcelableExtra(ADDRESS_EXTRA);
    final long threadId = intent.getLongExtra(THREAD_ID_EXTRA, -1);
    final CharSequence responseText = getMessageText(intent);
    final Recipient recipient = Recipient.from(context, address, false);
    if (responseText != null) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                long replyThreadId;
                int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
                long expiresIn = recipient.getExpireMessages() * 1000L;
                if (recipient.isGroupRecipient()) {
                    Log.w("AndroidAutoReplyReceiver", "GroupRecipient, Sending media message");
                    OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient, responseText.toString(), new LinkedList<>(), System.currentTimeMillis(), subscriptionId, expiresIn, 0);
                    replyThreadId = MessageSender.send(context, reply, threadId, false, null);
                } else {
                    Log.w("AndroidAutoReplyReceiver", "Sending regular message ");
                    OutgoingTextMessage reply = new OutgoingTextMessage(recipient, responseText.toString(), expiresIn, subscriptionId);
                    replyThreadId = MessageSender.send(context, reply, threadId, false, null);
                }
                List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(replyThreadId, true);
                MessageNotifier.updateNotification(context);
                MarkReadReceiver.process(context, messageIds);
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) Address(org.thoughtcrime.securesms.database.Address) Bundle(android.os.Bundle) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) SuppressLint(android.annotation.SuppressLint)

Aggregations

OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)14 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)6 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 Recipients (org.thoughtcrime.securesms.recipients.Recipients)5 Context (android.content.Context)4 Bundle (android.os.Bundle)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 OutgoingEndSessionMessage (org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage)4 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)4 Address (org.thoughtcrime.securesms.database.Address)3 OutgoingEncryptedMessage (org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage)3 SuppressLint (android.annotation.SuppressLint)2 AsyncTask (android.os.AsyncTask)2 AlertDialog (android.support.v7.app.AlertDialog)2 URISyntaxException (java.net.URISyntaxException)2 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)2 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)2 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)2 Rfc5724Uri (org.thoughtcrime.securesms.util.Rfc5724Uri)2