Search in sources :

Example 11 with MarkedMessageInfo

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

the class ConversationListFragment method handleMarkAllRead.

private void handleMarkAllRead() {
    Context context = requireContext();
    SignalExecutors.BOUNDED.execute(() -> {
        List<MarkedMessageInfo> messageIds = SignalDatabase.threads().setAllThreadsRead();
        ApplicationDependencies.getMessageNotifier().updateNotification(context);
        MarkReadReceiver.process(context, messageIds);
    });
}
Also used : Context(android.content.Context) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo)

Example 12 with MarkedMessageInfo

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

the class ThreadDatabase method setReadSince.

public List<MarkedMessageInfo> setReadSince(Map<Long, Long> threadIdToSinceTimestamp, boolean lastSeen) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    List<MarkedMessageInfo> smsRecords = new LinkedList<>();
    List<MarkedMessageInfo> mmsRecords = new LinkedList<>();
    boolean needsSync = false;
    db.beginTransaction();
    try {
        ContentValues contentValues = new ContentValues(2);
        contentValues.put(READ, ReadStatus.READ.serialize());
        for (Map.Entry<Long, Long> entry : threadIdToSinceTimestamp.entrySet()) {
            long threadId = entry.getKey();
            long sinceTimestamp = entry.getValue();
            if (lastSeen) {
                contentValues.put(LAST_SEEN, sinceTimestamp == -1 ? System.currentTimeMillis() : sinceTimestamp);
            }
            ThreadRecord previous = getThreadRecord(threadId);
            smsRecords.addAll(SignalDatabase.sms().setMessagesReadSince(threadId, sinceTimestamp));
            mmsRecords.addAll(SignalDatabase.mms().setMessagesReadSince(threadId, sinceTimestamp));
            SignalDatabase.sms().setReactionsSeen(threadId, sinceTimestamp);
            SignalDatabase.mms().setReactionsSeen(threadId, sinceTimestamp);
            int unreadCount = SignalDatabase.mmsSms().getUnreadCount(threadId);
            contentValues.put(UNREAD_COUNT, unreadCount);
            db.update(TABLE_NAME, contentValues, ID_WHERE, SqlUtil.buildArgs(threadId));
            if (previous != null && previous.isForcedUnread()) {
                SignalDatabase.recipients().markNeedsSync(previous.getRecipient().getId());
                needsSync = true;
            }
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    notifyVerboseConversationListeners(threadIdToSinceTimestamp.keySet());
    notifyConversationListListeners();
    if (needsSync) {
        StorageSyncHelper.scheduleSyncForDataChange();
    }
    return Util.concatenatedList(smsRecords, mmsRecords);
}
Also used : ContentValues(android.content.ContentValues) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) Map(java.util.Map) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 13 with MarkedMessageInfo

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

the class SendViewedReceiptJob method enqueue.

/**
 * Enqueues all the necessary jobs for viewed receipts, ensuring that they're all within the
 * maximum size.
 */
public static void enqueue(long threadId, @NonNull RecipientId recipientId, List<MarkedMessageInfo> markedMessageInfos) {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    List<List<MarkedMessageInfo>> messageIdChunks = ListUtil.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 SendViewedReceiptJob(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) MAX_TIMESTAMPS(org.thoughtcrime.securesms.jobs.SendReadReceiptJob.MAX_TIMESTAMPS) 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) ListUtil(org.signal.core.util.ListUtil) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) 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) 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) Collections(java.util.Collections) 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 14 with MarkedMessageInfo

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

the class MarkReadReceiver method onReceive.

@SuppressLint("StaticFieldLeak")
@Override
public void onReceive(final Context context, Intent intent) {
    if (!CLEAR_ACTION.equals(intent.getAction()))
        return;
    final ArrayList<ConversationId> threads = intent.getParcelableArrayListExtra(THREADS_EXTRA);
    if (threads != null) {
        MessageNotifier notifier = ApplicationDependencies.getMessageNotifier();
        for (ConversationId thread : threads) {
            notifier.removeStickyThread(thread);
        }
        NotificationCancellationHelper.cancelLegacy(context, intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1));
        PendingResult finisher = goAsync();
        SignalExecutors.BOUNDED.execute(() -> {
            List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();
            for (ConversationId thread : threads) {
                Log.i(TAG, "Marking as read: " + thread);
                List<MarkedMessageInfo> messageIds = SignalDatabase.threads().setRead(thread, true);
                messageIdsCollection.addAll(messageIds);
            }
            process(context, messageIdsCollection);
            ApplicationDependencies.getMessageNotifier().updateNotification(context);
            finisher.finish();
        });
    }
}
Also used : ConversationId(org.thoughtcrime.securesms.notifications.v2.ConversationId) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) LinkedList(java.util.LinkedList) SuppressLint(android.annotation.SuppressLint)

Example 15 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);
    final long groupStoryId = intent.getLongExtra(GROUP_STORY_ID_EXTRA, Long.MIN_VALUE);
    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().orElse(-1);
            long expiresIn = TimeUnit.SECONDS.toMillis(recipient.getExpiresInSeconds());
            ParentStoryId parentStoryId = groupStoryId != Long.MIN_VALUE ? ParentStoryId.deserialize(groupStoryId) : null;
            switch(replyMethod) {
                case GroupMessage:
                    {
                        OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient, responseText.toString(), new LinkedList<>(), System.currentTimeMillis(), subscriptionId, expiresIn, false, 0, StoryType.NONE, parentStoryId, false, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptySet(), Collections.emptySet(), null);
                        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(new ConversationId(threadId, groupStoryId != Long.MIN_VALUE ? groupStoryId : null), 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) ConversationId(org.thoughtcrime.securesms.notifications.v2.ConversationId) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Bundle(android.os.Bundle) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ParentStoryId(org.thoughtcrime.securesms.database.model.ParentStoryId) 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)26 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)12 LinkedList (java.util.LinkedList)11 Context (android.content.Context)9 NonNull (androidx.annotation.NonNull)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)8 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