Search in sources :

Example 1 with ResendMessageJob

use of org.thoughtcrime.securesms.jobs.ResendMessageJob in project Signal-Android by WhisperSystems.

the class MessageContentProcessor method handleSenderKeyRetryReceipt.

private void handleSenderKeyRetryReceipt(@NonNull Recipient requester, @Nullable MessageLogEntry messageLogEntry, @NonNull SignalServiceContent content, @NonNull DecryptionErrorMessage decryptionErrorMessage) {
    long sentTimestamp = decryptionErrorMessage.getTimestamp();
    MessageRecord relatedMessage = findRetryReceiptRelatedMessage(context, messageLogEntry, sentTimestamp);
    if (relatedMessage == null) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] The related message could not be found! There shouldn't be any sender key resends where we can't find the related message. Skipping.");
        return;
    }
    Recipient threadRecipient = SignalDatabase.threads().getRecipientForThreadId(relatedMessage.getThreadId());
    if (threadRecipient == null) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Could not find a thread recipient! Skipping.");
        return;
    }
    if (!threadRecipient.isPushV2Group()) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Thread recipient is not a v2 group! Skipping.");
        return;
    }
    GroupId.V2 groupId = threadRecipient.requireGroupId().requireV2();
    DistributionId distributionId = SignalDatabase.groups().getOrCreateDistributionId(groupId);
    SignalProtocolAddress requesterAddress = new SignalProtocolAddress(requester.requireServiceId().toString(), content.getSenderDevice());
    SignalDatabase.senderKeyShared().delete(distributionId, Collections.singleton(requesterAddress));
    if (messageLogEntry != null) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Found MSL entry for " + requester.getId() + " (" + requesterAddress + ") with timestamp " + sentTimestamp + ". Scheduling a resend.");
        ApplicationDependencies.getJobManager().add(new ResendMessageJob(messageLogEntry.getRecipientId(), messageLogEntry.getDateSent(), messageLogEntry.getContent(), messageLogEntry.getContentHint(), groupId, distributionId));
    } else {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Unable to find MSL entry for " + requester.getId() + " (" + requesterAddress + ") with timestamp " + sentTimestamp + ".");
        Optional<GroupRecord> groupRecord = SignalDatabase.groups().getGroup(groupId);
        if (!groupRecord.isPresent()) {
            warn(content.getTimestamp(), "[RetryReceipt-SK] Could not find a record for the group!");
            return;
        }
        if (!groupRecord.get().getMembers().contains(requester.getId())) {
            warn(content.getTimestamp(), "[RetryReceipt-SK] The requester is not in the group, so we cannot send them a SenderKeyDistributionMessage.");
            return;
        }
        warn(content.getTimestamp(), "[RetryReceipt-SK] The requester is in the group, so we'll send them a SenderKeyDistributionMessage.");
        ApplicationDependencies.getJobManager().add(new SenderKeyDistributionSendJob(requester.getId(), groupRecord.get().getId().requireV2()));
    }
}
Also used : SenderKeyDistributionSendJob(org.thoughtcrime.securesms.jobs.SenderKeyDistributionSendJob) ResendMessageJob(org.thoughtcrime.securesms.jobs.ResendMessageJob) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 2 with ResendMessageJob

use of org.thoughtcrime.securesms.jobs.ResendMessageJob in project Signal-Android by WhisperSystems.

the class MessageContentProcessor method handleIndividualRetryReceipt.

private void handleIndividualRetryReceipt(@NonNull Recipient requester, @Nullable MessageLogEntry messageLogEntry, @NonNull SignalServiceContent content, @NonNull DecryptionErrorMessage decryptionErrorMessage) {
    boolean archivedSession = false;
    if (decryptionErrorMessage.getRatchetKey().isPresent() && ratchetKeyMatches(requester, content.getSenderDevice(), decryptionErrorMessage.getRatchetKey().get())) {
        warn(content.getTimestamp(), "[RetryReceipt-I] Ratchet key matches. Archiving the session.");
        ApplicationDependencies.getProtocolStore().aci().sessions().archiveSession(requester.getId(), content.getSenderDevice());
        archivedSession = true;
    }
    if (messageLogEntry != null) {
        warn(content.getTimestamp(), "[RetryReceipt-I] Found an entry in the MSL. Resending.");
        ApplicationDependencies.getJobManager().add(new ResendMessageJob(messageLogEntry.getRecipientId(), messageLogEntry.getDateSent(), messageLogEntry.getContent(), messageLogEntry.getContentHint(), null, null));
    } else if (archivedSession) {
        warn(content.getTimestamp(), "[RetryReceipt-I] Could not find an entry in the MSL, but we archived the session, so we're sending a null message to complete the reset.");
        ApplicationDependencies.getJobManager().add(new NullMessageSendJob(requester.getId()));
    } else {
        warn(content.getTimestamp(), "[RetryReceipt-I] Could not find an entry in the MSL. Skipping.");
    }
}
Also used : ResendMessageJob(org.thoughtcrime.securesms.jobs.ResendMessageJob) NullMessageSendJob(org.thoughtcrime.securesms.jobs.NullMessageSendJob)

Example 3 with ResendMessageJob

use of org.thoughtcrime.securesms.jobs.ResendMessageJob in project Signal-Android by signalapp.

the class MessageContentProcessor method handleSenderKeyRetryReceipt.

private void handleSenderKeyRetryReceipt(@NonNull Recipient requester, @Nullable MessageLogEntry messageLogEntry, @NonNull SignalServiceContent content, @NonNull DecryptionErrorMessage decryptionErrorMessage) {
    long sentTimestamp = decryptionErrorMessage.getTimestamp();
    MessageRecord relatedMessage = findRetryReceiptRelatedMessage(context, messageLogEntry, sentTimestamp);
    if (relatedMessage == null) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] The related message could not be found! There shouldn't be any sender key resends where we can't find the related message. Skipping.");
        return;
    }
    Recipient threadRecipient = SignalDatabase.threads().getRecipientForThreadId(relatedMessage.getThreadId());
    if (threadRecipient == null) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Could not find a thread recipient! Skipping.");
        return;
    }
    if (!threadRecipient.isPushV2Group()) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Thread recipient is not a v2 group! Skipping.");
        return;
    }
    GroupId.V2 groupId = threadRecipient.requireGroupId().requireV2();
    DistributionId distributionId = SignalDatabase.groups().getOrCreateDistributionId(groupId);
    SignalProtocolAddress requesterAddress = new SignalProtocolAddress(requester.requireServiceId().toString(), content.getSenderDevice());
    SignalDatabase.senderKeyShared().delete(distributionId, Collections.singleton(requesterAddress));
    if (messageLogEntry != null) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Found MSL entry for " + requester.getId() + " (" + requesterAddress + ") with timestamp " + sentTimestamp + ". Scheduling a resend.");
        ApplicationDependencies.getJobManager().add(new ResendMessageJob(messageLogEntry.getRecipientId(), messageLogEntry.getDateSent(), messageLogEntry.getContent(), messageLogEntry.getContentHint(), groupId, distributionId));
    } else {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Unable to find MSL entry for " + requester.getId() + " (" + requesterAddress + ") with timestamp " + sentTimestamp + ".");
        Optional<GroupRecord> groupRecord = SignalDatabase.groups().getGroup(groupId);
        if (!groupRecord.isPresent()) {
            warn(content.getTimestamp(), "[RetryReceipt-SK] Could not find a record for the group!");
            return;
        }
        if (!groupRecord.get().getMembers().contains(requester.getId())) {
            warn(content.getTimestamp(), "[RetryReceipt-SK] The requester is not in the group, so we cannot send them a SenderKeyDistributionMessage.");
            return;
        }
        warn(content.getTimestamp(), "[RetryReceipt-SK] The requester is in the group, so we'll send them a SenderKeyDistributionMessage.");
        ApplicationDependencies.getJobManager().add(new SenderKeyDistributionSendJob(requester.getId(), groupRecord.get().getId().requireV2()));
    }
}
Also used : SenderKeyDistributionSendJob(org.thoughtcrime.securesms.jobs.SenderKeyDistributionSendJob) ResendMessageJob(org.thoughtcrime.securesms.jobs.ResendMessageJob) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 4 with ResendMessageJob

use of org.thoughtcrime.securesms.jobs.ResendMessageJob in project Signal-Android by signalapp.

the class MessageContentProcessor method handleIndividualRetryReceipt.

private void handleIndividualRetryReceipt(@NonNull Recipient requester, @Nullable MessageLogEntry messageLogEntry, @NonNull SignalServiceContent content, @NonNull DecryptionErrorMessage decryptionErrorMessage) {
    boolean archivedSession = false;
    if (decryptionErrorMessage.getRatchetKey().isPresent() && ratchetKeyMatches(requester, content.getSenderDevice(), decryptionErrorMessage.getRatchetKey().get())) {
        warn(content.getTimestamp(), "[RetryReceipt-I] Ratchet key matches. Archiving the session.");
        ApplicationDependencies.getProtocolStore().aci().sessions().archiveSession(requester.getId(), content.getSenderDevice());
        archivedSession = true;
    }
    if (messageLogEntry != null) {
        warn(content.getTimestamp(), "[RetryReceipt-I] Found an entry in the MSL. Resending.");
        ApplicationDependencies.getJobManager().add(new ResendMessageJob(messageLogEntry.getRecipientId(), messageLogEntry.getDateSent(), messageLogEntry.getContent(), messageLogEntry.getContentHint(), null, null));
    } else if (archivedSession) {
        warn(content.getTimestamp(), "[RetryReceipt-I] Could not find an entry in the MSL, but we archived the session, so we're sending a null message to complete the reset.");
        ApplicationDependencies.getJobManager().add(new NullMessageSendJob(requester.getId()));
    } else {
        warn(content.getTimestamp(), "[RetryReceipt-I] Could not find an entry in the MSL. Skipping.");
    }
}
Also used : ResendMessageJob(org.thoughtcrime.securesms.jobs.ResendMessageJob) NullMessageSendJob(org.thoughtcrime.securesms.jobs.NullMessageSendJob)

Aggregations

ResendMessageJob (org.thoughtcrime.securesms.jobs.ResendMessageJob)4 GroupRecord (org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)2 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)2 MmsMessageRecord (org.thoughtcrime.securesms.database.model.MmsMessageRecord)2 GroupId (org.thoughtcrime.securesms.groups.GroupId)2 NullMessageSendJob (org.thoughtcrime.securesms.jobs.NullMessageSendJob)2 SenderKeyDistributionSendJob (org.thoughtcrime.securesms.jobs.SenderKeyDistributionSendJob)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)2 DistributionId (org.whispersystems.signalservice.api.push.DistributionId)2