Search in sources :

Example 26 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class WebRtcCallService method getRemoteRecipient.

///
@NonNull
private Recipient getRemoteRecipient(Intent intent) {
    String remoteNumber = intent.getStringExtra(EXTRA_REMOTE_NUMBER);
    if (TextUtils.isEmpty(remoteNumber))
        throw new AssertionError("No recipient in intent!");
    Recipients recipients = RecipientFactory.getRecipientsFromString(this, remoteNumber, true);
    Recipient result = recipients.getPrimaryRecipient();
    if (result == null)
        throw new AssertionError("Recipient lookup failed!");
    else
        return result;
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NonNull(android.support.annotation.NonNull)

Example 27 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients 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 28 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class MessageSender method resendGroupMessage.

public static void resendGroupMessage(Context context, MasterSecret masterSecret, MessageRecord messageRecord, long filterRecipientId) {
    if (!messageRecord.isMms())
        throw new AssertionError("Not Group");
    Recipients recipients = DatabaseFactory.getMmsAddressDatabase(context).getRecipientsForId(messageRecord.getId());
    sendGroupPush(context, recipients, messageRecord.getId(), filterRecipientId);
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients)

Example 29 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class MessageSender method resend.

public static void resend(Context context, MasterSecret masterSecret, MessageRecord messageRecord) {
    try {
        long messageId = messageRecord.getId();
        boolean forceSms = messageRecord.isForcedSms();
        boolean keyExchange = messageRecord.isKeyExchange();
        long expiresIn = messageRecord.getExpiresIn();
        if (messageRecord.isMms()) {
            Recipients recipients = DatabaseFactory.getMmsAddressDatabase(context).getRecipientsForId(messageId);
            sendMediaMessage(context, masterSecret, recipients, forceSms, messageId, expiresIn);
        } else {
            Recipients recipients = messageRecord.getRecipients();
            sendTextMessage(context, recipients, forceSms, keyExchange, messageId, expiresIn);
        }
    } catch (MmsException e) {
        Log.w(TAG, e);
    }
}
Also used : MmsException(ws.com.google.android.mms.MmsException) Recipients(org.thoughtcrime.securesms.recipients.Recipients)

Example 30 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleTextMessage.

private void handleTextMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    String body = message.getBody().isPresent() ? message.getBody().get() : "";
    Recipients recipients = getMessageDestination(envelope, message);
    if (message.getExpiresInSeconds() != recipients.getExpireMessages()) {
        handleExpirationUpdate(masterSecret, envelope, message, Optional.<Long>absent());
    }
    Long threadId;
    if (smsMessageId.isPresent() && !message.getGroupInfo().isPresent()) {
        threadId = database.updateBundleMessageBody(masterSecret, smsMessageId.get(), body).second;
    } else {
        IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), message.getTimestamp(), body, message.getGroupInfo(), message.getExpiresInSeconds() * 1000);
        textMessage = new IncomingEncryptedMessage(textMessage, body);
        Optional<InsertResult> insertResult = database.insertMessageInbox(masterSecret, textMessage);
        if (insertResult.isPresent())
            threadId = insertResult.get().getThreadId();
        else
            threadId = null;
        if (smsMessageId.isPresent())
            database.deleteMessage(smsMessageId.get());
    }
    if (threadId != null) {
        MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) IncomingEncryptedMessage(org.thoughtcrime.securesms.sms.IncomingEncryptedMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Aggregations

Recipients (org.thoughtcrime.securesms.recipients.Recipients)52 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)7 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)7 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)6 LinkedList (java.util.LinkedList)5 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)5 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)5 Intent (android.content.Intent)4 Bundle (android.os.Bundle)4 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)4 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)4 MmsException (ws.com.google.android.mms.MmsException)4 Cursor (android.database.Cursor)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 NonNull (android.support.annotation.NonNull)3 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)3 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)3