Search in sources :

Example 11 with OutgoingTextMessage

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

the class PushDecryptJob method handleSynchronizeSentEndSessionMessage.

private long handleSynchronizeSentEndSessionMessage(@NonNull SentTranscriptMessage message) {
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    Recipient recipient = getSyncMessageDestination(message);
    OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipient, "", -1);
    OutgoingEndSessionMessage outgoingEndSessionMessage = new OutgoingEndSessionMessage(outgoingTextMessage);
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
    if (!recipient.isGroupRecipient()) {
        SessionStore sessionStore = new TextSecureSessionStore(context);
        sessionStore.deleteAllSessions(recipient.getAddress().toPhoneString());
        SecurityEvent.broadcastSecurityUpdateEvent(context);
        long messageId = database.insertMessageOutbox(threadId, outgoingEndSessionMessage, false, message.getTimestamp(), null);
        database.markAsSent(messageId, true);
    }
    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) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Example 12 with OutgoingTextMessage

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

the class PushDecryptJob method handleSynchronizeSentTextMessage.

private long handleSynchronizeSentTextMessage(@NonNull SentTranscriptMessage message) throws MmsException {
    Recipient recipient = getSyncMessageDestination(message);
    String body = message.getMessage().getBody().or("");
    long expiresInMillis = message.getMessage().getExpiresInSeconds() * 1000L;
    if (recipient.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
        handleSynchronizeSentExpirationUpdate(message);
    }
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
    MessagingDatabase database;
    long messageId;
    if (recipient.getAddress().isGroup()) {
        OutgoingMediaMessage outgoingMediaMessage = new OutgoingMediaMessage(recipient, new SlideDeck(), body, message.getTimestamp(), -1, expiresInMillis, ThreadDatabase.DistributionTypes.DEFAULT);
        outgoingMediaMessage = new OutgoingSecureMediaMessage(outgoingMediaMessage);
        messageId = DatabaseFactory.getMmsDatabase(context).insertMessageOutbox(outgoingMediaMessage, threadId, false, null);
        database = DatabaseFactory.getMmsDatabase(context);
    } else {
        OutgoingTextMessage outgoingTextMessage = new OutgoingEncryptedMessage(recipient, body, expiresInMillis);
        messageId = DatabaseFactory.getSmsDatabase(context).insertMessageOutbox(threadId, outgoingTextMessage, false, message.getTimestamp(), null);
        database = DatabaseFactory.getSmsDatabase(context);
    }
    database.markAsSent(messageId, true);
    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) MessagingDatabase(org.thoughtcrime.securesms.database.MessagingDatabase) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) OutgoingEncryptedMessage(org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck)

Example 13 with OutgoingTextMessage

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

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, (dialog, which) -> {
        if (isSingleConversation()) {
            final Context context = getApplicationContext();
            OutgoingEndSessionMessage endSessionMessage = new OutgoingEndSessionMessage(new OutgoingTextMessage(getRecipient(), "TERMINATE", 0, -1));
            new AsyncTask<OutgoingEndSessionMessage, Void, Long>() {

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

                @Override
                protected void onPostExecute(Long result) {
                    sendComplete(result);
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, 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)

Example 14 with OutgoingTextMessage

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

the class ConversationActivity method sendTextMessage.

private void sendTextMessage(final boolean forceSms, final long expiresIn, final int subscriptionId, final boolean initiatingConversation) throws InvalidMessageException {
    final Context context = getApplicationContext();
    final String messageBody = getMessage();
    OutgoingTextMessage message;
    if (isSecureText && !forceSms) {
        message = new OutgoingEncryptedMessage(recipient, messageBody, expiresIn);
    } else {
        message = new OutgoingTextMessage(recipient, messageBody, expiresIn, subscriptionId);
    }
    Permissions.with(this).request(Manifest.permission.SEND_SMS).ifNecessary(forceSms || !isSecureText).withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_sms_permission_in_order_to_send_an_sms)).onAllGranted(() -> {
        this.composeText.setText("");
        final long id = fragment.stageOutgoingMessage(message);
        new AsyncTask<OutgoingTextMessage, Void, Long>() {

            @Override
            protected Long doInBackground(OutgoingTextMessage... messages) {
                if (initiatingConversation) {
                    DatabaseFactory.getRecipientDatabase(context).setProfileSharing(recipient, true);
                }
                return MessageSender.send(context, messages[0], threadId, forceSms, () -> fragment.releaseOutgoingMessage(id));
            }

            @Override
            protected void onPostExecute(Long result) {
                sendComplete(result);
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, message);
    }).execute();
}
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) AsyncTask(android.os.AsyncTask) ByteString(com.google.protobuf.ByteString)

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