Search in sources :

Example 21 with Recipients

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

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

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

the class MessageNotifier method updateNotification.

public static void updateNotification(@NonNull Context context, @Nullable MasterSecret masterSecret, long threadId, boolean signal) {
    boolean isVisible = visibleThread == threadId;
    ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context);
    Recipients recipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
    if (isVisible) {
        List<MarkedMessageInfo> messageIds = threads.setRead(threadId, false);
        MarkReadReceiver.process(context, messageIds);
    }
    if (!TextSecurePreferences.isNotificationsEnabled(context) || (recipients != null && recipients.isMuted())) {
        return;
    }
    if (isVisible) {
        sendInThreadNotification(context, threads.getRecipientsForThreadId(threadId));
    } else {
        updateNotification(context, masterSecret, signal, 0);
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo)

Example 24 with Recipients

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

the class MessageNotifier method constructNotificationState.

private static NotificationState constructNotificationState(@NonNull Context context, @Nullable MasterSecret masterSecret, @NonNull Cursor cursor) {
    NotificationState notificationState = new NotificationState();
    MessageRecord record;
    MmsSmsDatabase.Reader reader;
    if (masterSecret == null)
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor);
    else
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret);
    while ((record = reader.getNext()) != null) {
        long id = record.getId();
        boolean mms = record.isMms() || record.isMmsNotification();
        Recipient recipient = record.getIndividualRecipient();
        Recipients recipients = record.getRecipients();
        long threadId = record.getThreadId();
        CharSequence body = record.getDisplayBody();
        Recipients threadRecipients = null;
        SlideDeck slideDeck = null;
        long timestamp = record.getTimestamp();
        if (threadId != -1) {
            threadRecipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
        }
        if (SmsDatabase.Types.isDecryptInProgressType(record.getType()) || !record.getBody().isPlaintext()) {
            body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message));
        } else if (record.isMms() && TextUtils.isEmpty(body)) {
            body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message));
            slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
        } else if (record.isMms() && !record.isMmsNotification()) {
            String message = context.getString(R.string.MessageNotifier_media_message_with_text, body);
            int italicLength = message.length() - body.length();
            body = SpanUtil.italic(message, italicLength);
            slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
        }
        if (threadRecipients == null || !threadRecipients.isMuted()) {
            notificationState.addNotification(new NotificationItem(id, mms, recipient, recipients, threadRecipients, threadId, body, timestamp, slideDeck));
        }
    }
    reader.close();
    return notificationState;
}
Also used : MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) Recipients(org.thoughtcrime.securesms.recipients.Recipients) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)

Example 25 with Recipients

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

the class NotificationItem method getPendingIntent.

public PendingIntent getPendingIntent(Context context) {
    Intent intent = new Intent(context, ConversationActivity.class);
    Recipients notifyRecipients = threadRecipients != null ? threadRecipients : recipients;
    if (notifyRecipients != null)
        intent.putExtra("recipients", notifyRecipients.getIds());
    intent.putExtra("thread_id", threadId);
    intent.setData((Uri.parse("custom://" + System.currentTimeMillis())));
    return TaskStackBuilder.create(context).addNextIntentWithParentStack(intent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

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