use of org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob in project Signal-Android by WhisperSystems.
the class MarkReadReceiverTest method givenMultipleThreadsWithMultipleMessagesEach_whenIProcess_thenIProperlyGroupByThreadAndRecipient.
@Test
public void givenMultipleThreadsWithMultipleMessagesEach_whenIProcess_thenIProperlyGroupByThreadAndRecipient() {
// GIVEN
List<RecipientId> recipients = Stream.range(1L, 4L).map(RecipientId::from).toList();
List<Long> threads = Stream.range(4L, 7L).toList();
int expected = recipients.size() * threads.size() + 1;
List<MessageDatabase.MarkedMessageInfo> infoList = Stream.of(threads).flatMap(threadId -> Stream.of(recipients).map(recipientId -> createMarkedMessageInfo(threadId, recipientId))).toList();
List<MessageDatabase.MarkedMessageInfo> duplicatedList = Util.concatenatedList(infoList, infoList);
// WHEN
MarkReadReceiver.process(mockContext, duplicatedList);
// THEN
assertEquals("Should have 10 total jobs, including MultiDeviceReadUpdateJob", expected, jobs.size());
Set<Pair<Long, String>> threadRecipientPairs = new HashSet<>();
Stream.of(jobs).forEach(job -> {
if (job instanceof MultiDeviceReadUpdateJob) {
return;
}
Data data = job.serialize();
long threadId = data.getLong("thread");
String recipientId = data.getString("recipient");
long[] messageIds = data.getLongArray("message_ids");
assertEquals("Each job should contain two messages.", 2, messageIds.length);
assertTrue("Each thread recipient pair should only exist once.", threadRecipientPairs.add(new Pair<>(threadId, recipientId)));
});
assertEquals("Should have 9 total combinations.", 9, threadRecipientPairs.size());
}
use of org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob 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 = new LinkedList<>();
for (MarkedMessageInfo messageInfo : markedReadMessages) {
scheduleDeletion(context, messageInfo.getExpirationInfo());
syncMessageIds.add(messageInfo.getSyncMessageId());
}
ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceReadUpdateJob(context, syncMessageIds));
Map<Address, List<SyncMessageId>> addressMap = Stream.of(markedReadMessages).map(MarkedMessageInfo::getSyncMessageId).collect(Collectors.groupingBy(SyncMessageId::getAddress));
for (Address address : addressMap.keySet()) {
List<Long> timestamps = Stream.of(addressMap.get(address)).map(SyncMessageId::getTimetamp).toList();
ApplicationContext.getInstance(context).getJobManager().add(new SendReadReceiptJob(context, address, timestamps));
}
}
use of org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob in project Signal-Android by WhisperSystems.
the class RecipientIdJobMigrationTest method migrate_multiDeviceReadUpdateJob_twoIds.
@Test
public void migrate_multiDeviceReadUpdateJob_twoIds() throws Exception {
OldSerializableSyncMessageId id1 = new OldSerializableSyncMessageId("+16101234567", 1);
OldSerializableSyncMessageId id2 = new OldSerializableSyncMessageId("+16101112222", 2);
JobData testData = new JobData("MultiDeviceReadUpdateJob", null, new Data.Builder().putStringArray("message_ids", new String[] { JsonUtils.toJson(id1), JsonUtils.toJson(id2) }).build());
mockRecipientResolve("+16101234567", 1);
mockRecipientResolve("+16101112222", 2);
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
JobData converted = subject.migrate(testData);
assertEquals("MultiDeviceReadUpdateJob", converted.getFactoryKey());
assertNull(converted.getQueueKey());
String[] updated = converted.getData().getStringArray("message_ids");
assertEquals(2, updated.length);
assertEquals(JsonUtils.toJson(new NewSerializableSyncMessageId("1", 1)), updated[0]);
assertEquals(JsonUtils.toJson(new NewSerializableSyncMessageId("2", 2)), updated[1]);
new MultiDeviceReadUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
use of org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob in project Signal-Android by WhisperSystems.
the class RecipientIdJobMigrationTest method migrate_multiDeviceReadUpdateJob_empty.
@Test
public void migrate_multiDeviceReadUpdateJob_empty() throws Exception {
JobData testData = new JobData("MultiDeviceReadUpdateJob", null, new Data.Builder().putStringArray("message_ids", new String[0]).build());
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
JobData converted = subject.migrate(testData);
assertEquals("MultiDeviceReadUpdateJob", converted.getFactoryKey());
assertNull(converted.getQueueKey());
assertEquals(0, converted.getData().getStringArray("message_ids").length);
new MultiDeviceReadUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Aggregations