Search in sources :

Example 1 with Job

use of org.thoughtcrime.securesms.jobmanager.Job 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 2 with Job

use of org.thoughtcrime.securesms.jobmanager.Job 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 3 with Job

use of org.thoughtcrime.securesms.jobmanager.Job 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)

Example 4 with Job

use of org.thoughtcrime.securesms.jobmanager.Job in project Signal-Android by WhisperSystems.

the class RetrieveProfileJob method forRecipients.

/**
 * Works for any RecipientId, whether it's an individual, group, or yourself.
 *
 * @return A list of length 2 or less. Two iff you are in the recipients.
 */
@WorkerThread
@NonNull
public static List<Job> forRecipients(@NonNull Set<RecipientId> recipientIds) {
    Context context = ApplicationDependencies.getApplication();
    Set<RecipientId> combined = new HashSet<>(recipientIds.size());
    boolean includeSelf = false;
    for (RecipientId recipientId : recipientIds) {
        Recipient recipient = Recipient.resolved(recipientId);
        if (recipient.isSelf()) {
            includeSelf = true;
        } else if (recipient.isGroup()) {
            List<Recipient> recipients = SignalDatabase.groups().getGroupMembers(recipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
            combined.addAll(Stream.of(recipients).map(Recipient::getId).toList());
        } else {
            combined.add(recipientId);
        }
    }
    List<Job> jobs = new ArrayList<>(2);
    if (includeSelf) {
        jobs.add(new RefreshOwnProfileJob());
    }
    if (combined.size() > 0) {
        jobs.add(new RetrieveProfileJob(combined));
    }
    return jobs;
}
Also used : Context(android.content.Context) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) List(java.util.List) ArrayList(java.util.ArrayList) Job(org.thoughtcrime.securesms.jobmanager.Job) HashSet(java.util.HashSet) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 5 with Job

use of org.thoughtcrime.securesms.jobmanager.Job in project Signal-Android by WhisperSystems.

the class PushDecryptMessageJob method onRun.

@Override
public void onRun() throws RetryLaterException {
    if (needsMigration()) {
        Log.w(TAG, "Migration is still needed.");
        postMigrationNotification();
        throw new RetryLaterException();
    }
    List<Job> jobs = new LinkedList<>();
    DecryptionResult result = MessageDecryptionUtil.decrypt(context, envelope);
    if (result.getContent() != null) {
        if (result.getContent().getSenderKeyDistributionMessage().isPresent()) {
            handleSenderKeyDistributionMessage(result.getContent().getSender(), result.getContent().getSenderDevice(), result.getContent().getSenderKeyDistributionMessage().get());
        }
        jobs.add(new PushProcessMessageJob(result.getContent(), smsMessageId, envelope.getTimestamp()));
    } else if (result.getException() != null && result.getState() != MessageState.NOOP) {
        jobs.add(new PushProcessMessageJob(result.getState(), result.getException(), smsMessageId, envelope.getTimestamp()));
    }
    jobs.addAll(result.getJobs());
    for (Job job : jobs) {
        ApplicationDependencies.getJobManager().add(job);
    }
}
Also used : DecryptionResult(org.thoughtcrime.securesms.messages.MessageDecryptionUtil.DecryptionResult) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) Job(org.thoughtcrime.securesms.jobmanager.Job) LinkedList(java.util.LinkedList)

Aggregations

Job (org.thoughtcrime.securesms.jobmanager.Job)26 JobManager (org.thoughtcrime.securesms.jobmanager.JobManager)16 NonNull (androidx.annotation.NonNull)14 Recipient (org.thoughtcrime.securesms.recipients.Recipient)12 WorkerThread (androidx.annotation.WorkerThread)10 List (java.util.List)10 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)10 Context (android.content.Context)8 Stream (com.annimon.stream.Stream)8 IOException (java.io.IOException)8 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)8 AttachmentCompressionJob (org.thoughtcrime.securesms.jobs.AttachmentCompressionJob)8 AttachmentCopyJob (org.thoughtcrime.securesms.jobs.AttachmentCopyJob)8 AttachmentMarkUploadedJob (org.thoughtcrime.securesms.jobs.AttachmentMarkUploadedJob)8 AttachmentUploadJob (org.thoughtcrime.securesms.jobs.AttachmentUploadJob)8 MmsSendJob (org.thoughtcrime.securesms.jobs.MmsSendJob)8 ProfileKeySendJob (org.thoughtcrime.securesms.jobs.ProfileKeySendJob)8 PushGroupSendJob (org.thoughtcrime.securesms.jobs.PushGroupSendJob)8 PushMediaSendJob (org.thoughtcrime.securesms.jobs.PushMediaSendJob)8 PushTextSendJob (org.thoughtcrime.securesms.jobs.PushTextSendJob)8