use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by WhisperSystems.
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));
}
}
use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by WhisperSystems.
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 = 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 SendViewedReceiptJob(threadId, recipientId, sentTimestamps, messageIds));
}
}
use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by WhisperSystems.
the class StickerPackDownloadJob method onRun.
@Override
protected void onRun() throws IOException, InvalidMessageException {
if (isReferencePack && !SignalDatabase.attachments().containsStickerPackId(packId) && !BlessedPacks.contains(packId)) {
Log.w(TAG, "There are no attachments with the requested packId present for this reference pack. Skipping.");
return;
}
if (isReferencePack && SignalDatabase.stickers().isPackAvailableAsReference(packId)) {
Log.i(TAG, "Sticker pack already available for reference. Skipping.");
return;
}
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
JobManager jobManager = ApplicationDependencies.getJobManager();
StickerDatabase stickerDatabase = SignalDatabase.stickers();
byte[] packIdBytes = Hex.fromStringCondensed(packId);
byte[] packKeyBytes = Hex.fromStringCondensed(packKey);
SignalServiceStickerManifest manifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
if (manifest.getStickers().isEmpty()) {
Log.w(TAG, "No stickers in pack!");
return;
}
if (!isReferencePack && stickerDatabase.isPackAvailableAsReference(packId)) {
stickerDatabase.markPackAsInstalled(packId, notify);
}
StickerInfo cover = manifest.getCover().or(manifest.getStickers().get(0));
JobManager.Chain chain = jobManager.startChain(new StickerDownloadJob(new IncomingSticker(packId, packKey, manifest.getTitle().or(""), manifest.getAuthor().or(""), cover.getId(), "", cover.getContentType(), true, !isReferencePack), notify));
if (!isReferencePack) {
List<Job> jobs = new ArrayList<>(manifest.getStickers().size());
for (StickerInfo stickerInfo : manifest.getStickers()) {
jobs.add(new StickerDownloadJob(new IncomingSticker(packId, packKey, manifest.getTitle().or(""), manifest.getAuthor().or(""), stickerInfo.getId(), stickerInfo.getEmoji(), stickerInfo.getContentType(), false, true), notify));
}
chain.then(jobs);
}
chain.enqueue();
}
use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by WhisperSystems.
the class MessageSender method sendGroupPush.
private static void sendGroupPush(Context context, Recipient recipient, long messageId, RecipientId filterRecipientId, @NonNull Collection<String> uploadJobIds) {
JobManager jobManager = ApplicationDependencies.getJobManager();
if (uploadJobIds.size() > 0) {
Job groupSend = new PushGroupSendJob(messageId, recipient.getId(), filterRecipientId, !uploadJobIds.isEmpty());
jobManager.add(groupSend, uploadJobIds, uploadJobIds.isEmpty() ? null : recipient.getId().toQueueKey());
} else {
PushGroupSendJob.enqueue(context, jobManager, messageId, recipient.getId(), filterRecipientId);
}
}
use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by WhisperSystems.
the class MessageSender method sendMediaPush.
private static void sendMediaPush(Context context, Recipient recipient, long messageId, @NonNull Collection<String> uploadJobIds) {
JobManager jobManager = ApplicationDependencies.getJobManager();
if (uploadJobIds.size() > 0) {
Job mediaSend = new PushMediaSendJob(messageId, recipient, true);
jobManager.add(mediaSend, uploadJobIds);
} else {
PushMediaSendJob.enqueue(context, jobManager, messageId, recipient);
}
}
Aggregations