Search in sources :

Example 1 with ExpirationInfo

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

the class MarkReadReceiver method process.

public static void process(@NonNull Context context, @NonNull List<MarkedMessageInfo> markedReadMessages) {
    if (markedReadMessages.isEmpty())
        return;
    List<SyncMessageId> syncMessageIds = Stream.of(markedReadMessages).map(MarkedMessageInfo::getSyncMessageId).toList();
    List<ExpirationInfo> mmsExpirationInfo = Stream.of(markedReadMessages).map(MarkedMessageInfo::getExpirationInfo).filter(ExpirationInfo::isMms).filter(info -> info.getExpiresIn() > 0 && info.getExpireStarted() <= 0).toList();
    List<ExpirationInfo> smsExpirationInfo = Stream.of(markedReadMessages).map(MarkedMessageInfo::getExpirationInfo).filterNot(ExpirationInfo::isMms).filter(info -> info.getExpiresIn() > 0 && info.getExpireStarted() <= 0).toList();
    scheduleDeletion(context, smsExpirationInfo, mmsExpirationInfo);
    MultiDeviceReadUpdateJob.enqueue(syncMessageIds);
    Map<Long, List<MarkedMessageInfo>> threadToInfo = Stream.of(markedReadMessages).collect(Collectors.groupingBy(MarkedMessageInfo::getThreadId));
    Stream.of(threadToInfo).forEach(threadToInfoEntry -> {
        Map<RecipientId, List<MarkedMessageInfo>> recipientIdToInfo = Stream.of(threadToInfoEntry.getValue()).map(info -> info).collect(Collectors.groupingBy(info -> info.getSyncMessageId().getRecipientId()));
        Stream.of(recipientIdToInfo).forEach(entry -> {
            long threadId = threadToInfoEntry.getKey();
            RecipientId recipientId = entry.getKey();
            List<MarkedMessageInfo> infos = entry.getValue();
            SendReadReceiptJob.enqueue(threadId, recipientId, infos);
        });
    });
}
Also used : MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) NonNull(androidx.annotation.NonNull) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) SendReadReceiptJob(org.thoughtcrime.securesms.jobs.SendReadReceiptJob) ExpirationInfo(org.thoughtcrime.securesms.database.MessageDatabase.ExpirationInfo) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Log(org.signal.core.util.logging.Log) SuppressLint(android.annotation.SuppressLint) List(java.util.List) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MultiDeviceReadUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob) Map(java.util.Map) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) LinkedList(java.util.LinkedList) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ExpirationInfo(org.thoughtcrime.securesms.database.MessageDatabase.ExpirationInfo) List(java.util.List) LinkedList(java.util.LinkedList) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo)

Example 2 with ExpirationInfo

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

the class MarkReadReceiver method scheduleDeletion.

private static void scheduleDeletion(@NonNull Context context, @NonNull List<ExpirationInfo> smsExpirationInfo, @NonNull List<ExpirationInfo> mmsExpirationInfo) {
    if (smsExpirationInfo.size() > 0) {
        SignalDatabase.sms().markExpireStarted(Stream.of(smsExpirationInfo).map(ExpirationInfo::getId).toList(), System.currentTimeMillis());
    }
    if (mmsExpirationInfo.size() > 0) {
        SignalDatabase.mms().markExpireStarted(Stream.of(mmsExpirationInfo).map(ExpirationInfo::getId).toList(), System.currentTimeMillis());
    }
    if (smsExpirationInfo.size() + mmsExpirationInfo.size() > 0) {
        ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
        Stream.concat(Stream.of(smsExpirationInfo), Stream.of(mmsExpirationInfo)).forEach(info -> expirationManager.scheduleDeletion(info.getId(), info.isMms(), info.getExpiresIn()));
    }
}
Also used : ExpirationInfo(org.thoughtcrime.securesms.database.MessageDatabase.ExpirationInfo) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager)

Aggregations

ExpirationInfo (org.thoughtcrime.securesms.database.MessageDatabase.ExpirationInfo)2 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)2 SuppressLint (android.annotation.SuppressLint)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 NonNull (androidx.annotation.NonNull)1 Collectors (com.annimon.stream.Collectors)1 Stream (com.annimon.stream.Stream)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 SignalExecutors (org.signal.core.util.concurrent.SignalExecutors)1 Log (org.signal.core.util.logging.Log)1 MarkedMessageInfo (org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo)1 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)1 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)1 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)1 MultiDeviceReadUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob)1 SendReadReceiptJob (org.thoughtcrime.securesms.jobs.SendReadReceiptJob)1