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 = 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 SendReadReceiptJob(threadId, recipientId, sentTimestamps, messageIds));
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project Signal-Android by signalapp.
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);
});
});
}
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);
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);
});
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project mollyim-android by mollyim.
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);
});
});
}
use of org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo in project mollyim-android by mollyim.
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);
});
}
Aggregations