Search in sources :

Example 6 with OutgoingTextMessage

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

the class ConversationActivity method handleResetSecureSession.

private void handleResetSecureSession() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.ConversationActivity_reset_secure_session_question);
    builder.setIconAttribute(R.attr.dialog_alert_icon);
    builder.setCancelable(true);
    builder.setMessage(R.string.ConversationActivity_this_may_help_if_youre_having_encryption_problems);
    builder.setPositiveButton(R.string.ConversationActivity_reset, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (isSingleConversation()) {
                final Context context = getApplicationContext();
                OutgoingEndSessionMessage endSessionMessage = new OutgoingEndSessionMessage(new OutgoingTextMessage(getRecipients(), "TERMINATE", 0, -1));
                new AsyncTask<OutgoingEndSessionMessage, Void, Long>() {

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

                    @Override
                    protected void onPostExecute(Long result) {
                        sendComplete(result);
                    }
                }.execute(endSessionMessage);
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Context(android.content.Context) OutgoingEndSessionMessage(org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) DialogInterface(android.content.DialogInterface) AsyncTask(android.os.AsyncTask)

Example 7 with OutgoingTextMessage

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

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

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

the class QuickResponseService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
        Log.w(TAG, "Received unknown intent: " + intent.getAction());
        return;
    }
    if (KeyCachingService.isLocked(this)) {
        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 number = uri.getPath();
        if (number.contains("%")) {
            number = URLDecoder.decode(number);
        }
        Address address = Address.fromExternal(this, number);
        Recipient recipient = Recipient.from(this, address, false);
        int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
        long expiresIn = recipient.getExpireMessages() * 1000L;
        if (!TextUtils.isEmpty(content)) {
            MessageSender.send(this, new OutgoingTextMessage(recipient, content, expiresIn, subscriptionId), -1, false, null);
        }
    } 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) Address(org.thoughtcrime.securesms.database.Address) Recipient(org.thoughtcrime.securesms.recipients.Recipient) URISyntaxException(java.net.URISyntaxException)

Example 10 with OutgoingTextMessage

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

the class RemoteReplyReceiver 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 CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_REMOTE_REPLY);
    if (responseText != null) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                long threadId;
                Recipient recipient = Recipient.from(context, address, false);
                int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
                long expiresIn = recipient.getExpireMessages() * 1000L;
                if (recipient.isGroupRecipient()) {
                    OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient, responseText.toString(), new LinkedList<>(), System.currentTimeMillis(), subscriptionId, expiresIn, 0);
                    threadId = MessageSender.send(context, reply, -1, false, null);
                } else {
                    OutgoingTextMessage reply = new OutgoingTextMessage(recipient, responseText.toString(), expiresIn, subscriptionId);
                    threadId = MessageSender.send(context, reply, -1, false, null);
                }
                List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, 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