Search in sources :

Example 1 with JobManager

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));
    }
}
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) 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) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ArrayList(java.util.ArrayList) 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) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) 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) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) ArrayList(java.util.ArrayList) 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 2 with JobManager

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));
    }
}
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) 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 3 with JobManager

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();
}
Also used : SignalServiceStickerManifest(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) StickerDatabase(org.thoughtcrime.securesms.database.StickerDatabase) ArrayList(java.util.ArrayList) IncomingSticker(org.thoughtcrime.securesms.database.model.IncomingSticker) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) StickerInfo(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest.StickerInfo) Job(org.thoughtcrime.securesms.jobmanager.Job)

Example 4 with JobManager

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);
    }
}
Also used : PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) AttachmentMarkUploadedJob(org.thoughtcrime.securesms.jobs.AttachmentMarkUploadedJob) ReactionSendJob(org.thoughtcrime.securesms.jobs.ReactionSendJob) PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) Job(org.thoughtcrime.securesms.jobmanager.Job) ResumableUploadSpecJob(org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob) PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) AttachmentCompressionJob(org.thoughtcrime.securesms.jobs.AttachmentCompressionJob) ProfileKeySendJob(org.thoughtcrime.securesms.jobs.ProfileKeySendJob) RemoteDeleteSendJob(org.thoughtcrime.securesms.jobs.RemoteDeleteSendJob) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob) AttachmentUploadJob(org.thoughtcrime.securesms.jobs.AttachmentUploadJob) PushTextSendJob(org.thoughtcrime.securesms.jobs.PushTextSendJob) AttachmentCopyJob(org.thoughtcrime.securesms.jobs.AttachmentCopyJob) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob)

Example 5 with JobManager

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);
    }
}
Also used : PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) AttachmentMarkUploadedJob(org.thoughtcrime.securesms.jobs.AttachmentMarkUploadedJob) ReactionSendJob(org.thoughtcrime.securesms.jobs.ReactionSendJob) PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) Job(org.thoughtcrime.securesms.jobmanager.Job) ResumableUploadSpecJob(org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob) PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) AttachmentCompressionJob(org.thoughtcrime.securesms.jobs.AttachmentCompressionJob) ProfileKeySendJob(org.thoughtcrime.securesms.jobs.ProfileKeySendJob) RemoteDeleteSendJob(org.thoughtcrime.securesms.jobs.RemoteDeleteSendJob) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob) AttachmentUploadJob(org.thoughtcrime.securesms.jobs.AttachmentUploadJob) PushTextSendJob(org.thoughtcrime.securesms.jobs.PushTextSendJob) AttachmentCopyJob(org.thoughtcrime.securesms.jobs.AttachmentCopyJob) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob)

Aggregations

JobManager (org.thoughtcrime.securesms.jobmanager.JobManager)29 Job (org.thoughtcrime.securesms.jobmanager.Job)9 IOException (java.io.IOException)7 List (java.util.List)7 NonNull (androidx.annotation.NonNull)5 Log (org.signal.core.util.logging.Log)5 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)5 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)5 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)5 WorkerThread (androidx.annotation.WorkerThread)4 TimeUnit (java.util.concurrent.TimeUnit)4 SmsSendJob (org.thoughtcrime.securesms.jobs.SmsSendJob)4 Application (android.app.Application)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Data (org.thoughtcrime.securesms.jobmanager.Data)3 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)3 Util (org.thoughtcrime.securesms.util.Util)3 Stream (com.annimon.stream.Stream)2