Search in sources :

Example 16 with MarkedMessageInfo

use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project Signal-Android by WhisperSystems.

the class ThreadDatabase method setAllThreadsRead.

public List<MarkedMessageInfo> setAllThreadsRead() {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    ContentValues contentValues = new ContentValues(1);
    contentValues.put(READ, ReadStatus.READ.serialize());
    contentValues.put(UNREAD_COUNT, 0);
    db.update(TABLE_NAME, contentValues, null, null);
    final List<MarkedMessageInfo> smsRecords = SignalDatabase.sms().setAllMessagesRead();
    final List<MarkedMessageInfo> mmsRecords = SignalDatabase.mms().setAllMessagesRead();
    SignalDatabase.sms().setAllReactionsSeen();
    SignalDatabase.mms().setAllReactionsSeen();
    notifyConversationListListeners();
    return Util.concatenatedList(smsRecords, mmsRecords);
}
Also used : ContentValues(android.content.ContentValues) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo)

Example 17 with MarkedMessageInfo

use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project Signal-Android by WhisperSystems.

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 RecipientId recipientId = intent.getParcelableExtra(RECIPIENT_EXTRA);
    final ReplyMethod replyMethod = (ReplyMethod) intent.getSerializableExtra(REPLY_METHOD);
    final CharSequence responseText = remoteInput.getCharSequence(MessageNotifierV2.EXTRA_REMOTE_REPLY);
    if (recipientId == null)
        throw new AssertionError("No recipientId specified");
    if (replyMethod == null)
        throw new AssertionError("No reply method specified");
    if (responseText != null) {
        SignalExecutors.BOUNDED.execute(() -> {
            long threadId;
            Recipient recipient = Recipient.resolved(recipientId);
            int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
            long expiresIn = TimeUnit.SECONDS.toMillis(recipient.getExpiresInSeconds());
            switch(replyMethod) {
                case GroupMessage:
                    {
                        OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient, responseText.toString(), new LinkedList<>(), System.currentTimeMillis(), subscriptionId, expiresIn, false, 0, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptySet(), Collections.emptySet());
                        threadId = MessageSender.send(context, reply, -1, false, null, null);
                        break;
                    }
                case SecureMessage:
                    {
                        OutgoingEncryptedMessage reply = new OutgoingEncryptedMessage(recipient, responseText.toString(), expiresIn);
                        threadId = MessageSender.send(context, reply, -1, false, null, null);
                        break;
                    }
                case UnsecuredSmsMessage:
                    {
                        OutgoingTextMessage reply = new OutgoingTextMessage(recipient, responseText.toString(), expiresIn, subscriptionId);
                        threadId = MessageSender.send(context, reply, -1, true, null, null);
                        break;
                    }
                default:
                    throw new AssertionError("Unknown Reply method");
            }
            ApplicationDependencies.getMessageNotifier().addStickyThread(threadId, intent.getLongExtra(EARLIEST_TIMESTAMP, System.currentTimeMillis()));
            List<MarkedMessageInfo> messageIds = SignalDatabase.threads().setRead(threadId, true);
            ApplicationDependencies.getMessageNotifier().updateNotification(context);
            MarkReadReceiver.process(context, messageIds);
        });
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Bundle(android.os.Bundle) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SuppressLint(android.annotation.SuppressLint) LinkedList(java.util.LinkedList) OutgoingEncryptedMessage(org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) SuppressLint(android.annotation.SuppressLint)

Example 18 with MarkedMessageInfo

use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project Signal-Android by signalapp.

the class ThreadDatabase method setAllThreadsRead.

public List<MarkedMessageInfo> setAllThreadsRead() {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    ContentValues contentValues = new ContentValues(1);
    contentValues.put(READ, ReadStatus.READ.serialize());
    contentValues.put(UNREAD_COUNT, 0);
    db.update(TABLE_NAME, contentValues, null, null);
    final List<MarkedMessageInfo> smsRecords = SignalDatabase.sms().setAllMessagesRead();
    final List<MarkedMessageInfo> mmsRecords = SignalDatabase.mms().setAllMessagesRead();
    SignalDatabase.sms().setAllReactionsSeen();
    SignalDatabase.mms().setAllReactionsSeen();
    notifyConversationListListeners();
    return Util.concatenatedList(smsRecords, mmsRecords);
}
Also used : ContentValues(android.content.ContentValues) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo)

Example 19 with MarkedMessageInfo

use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project Signal-Android by signalapp.

the class SendReadReceiptJob method enqueue.

/**
 * Enqueues all the necessary jobs for read receipts, ensuring that they're all within the
 * maximum size.
 */
public static void enqueue(long threadId, @NonNull RecipientId recipientId, List<MarkedMessageInfo> markedMessageInfos) {
    if (recipientId.equals(Recipient.self().getId())) {
        return;
    }
    JobManager jobManager = ApplicationDependencies.getJobManager();
    List<List<MarkedMessageInfo>> messageIdChunks = Util.chunk(markedMessageInfos, MAX_TIMESTAMPS);
    if (messageIdChunks.size() > 1) {
        Log.w(TAG, "Large receipt count! Had to break into multiple chunks. Total count: " + markedMessageInfos.size());
    }
    for (List<MarkedMessageInfo> chunk : messageIdChunks) {
        List<Long> sentTimestamps = chunk.stream().map(info -> info.getSyncMessageId().getTimetamp()).collect(Collectors.toList());
        List<MessageId> messageIds = chunk.stream().map(MarkedMessageInfo::getMessageId).collect(Collectors.toList());
        jobManager.add(new SendReadReceiptJob(threadId, recipientId, sentTimestamps, messageIds));
    }
}
Also used : MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) ServerRejectedException(org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) Util(org.thoughtcrime.securesms.util.Util) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ArrayList(java.util.ArrayList) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) MessageId(org.thoughtcrime.securesms.database.model.MessageId) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) IOException(java.io.IOException) UnidentifiedAccessUtil(org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Application(android.app.Application) Job(org.thoughtcrime.securesms.jobmanager.Job) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) ArrayList(java.util.ArrayList) List(java.util.List) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 20 with MarkedMessageInfo

use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo 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 RecipientId recipientId = intent.getParcelableExtra(RECIPIENT_EXTRA);
    final ReplyMethod replyMethod = (ReplyMethod) intent.getSerializableExtra(REPLY_METHOD);
    final CharSequence responseText = remoteInput.getCharSequence(MessageNotifierV2.EXTRA_REMOTE_REPLY);
    if (recipientId == null)
        throw new AssertionError("No recipientId specified");
    if (replyMethod == null)
        throw new AssertionError("No reply method specified");
    if (responseText != null) {
        SignalExecutors.BOUNDED.execute(() -> {
            long threadId;
            Recipient recipient = Recipient.resolved(recipientId);
            int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
            long expiresIn = TimeUnit.SECONDS.toMillis(recipient.getExpiresInSeconds());
            switch(replyMethod) {
                case GroupMessage:
                    {
                        OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient, responseText.toString(), new LinkedList<>(), System.currentTimeMillis(), subscriptionId, expiresIn, false, 0, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptySet(), Collections.emptySet());
                        threadId = MessageSender.send(context, reply, -1, false, null, null);
                        break;
                    }
                case SecureMessage:
                    {
                        OutgoingEncryptedMessage reply = new OutgoingEncryptedMessage(recipient, responseText.toString(), expiresIn);
                        threadId = MessageSender.send(context, reply, -1, false, null, null);
                        break;
                    }
                case UnsecuredSmsMessage:
                    {
                        OutgoingTextMessage reply = new OutgoingTextMessage(recipient, responseText.toString(), expiresIn, subscriptionId);
                        threadId = MessageSender.send(context, reply, -1, true, null, null);
                        break;
                    }
                default:
                    throw new AssertionError("Unknown Reply method");
            }
            ApplicationDependencies.getMessageNotifier().addStickyThread(threadId, intent.getLongExtra(EARLIEST_TIMESTAMP, System.currentTimeMillis()));
            List<MarkedMessageInfo> messageIds = SignalDatabase.threads().setRead(threadId, true);
            ApplicationDependencies.getMessageNotifier().updateNotification(context);
            MarkReadReceiver.process(context, messageIds);
        });
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Bundle(android.os.Bundle) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SuppressLint(android.annotation.SuppressLint) LinkedList(java.util.LinkedList) OutgoingEncryptedMessage(org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) SuppressLint(android.annotation.SuppressLint)

Aggregations

MarkedMessageInfo (org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo)24 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)12 Context (android.content.Context)9 NonNull (androidx.annotation.NonNull)9 LinkedList (java.util.LinkedList)9 List (java.util.List)9 Log (org.signal.core.util.logging.Log)9 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)9 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)9 Recipient (org.thoughtcrime.securesms.recipients.Recipient)9 SuppressLint (android.annotation.SuppressLint)6 Application (android.app.Application)6 ContentValues (android.content.ContentValues)6 IOException (java.io.IOException)6 Collections (java.util.Collections)6 Map (java.util.Map)6 TimeUnit (java.util.concurrent.TimeUnit)6 Collectors (java.util.stream.Collectors)6 UnidentifiedAccessUtil (org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil)6 MessageId (org.thoughtcrime.securesms.database.model.MessageId)6