Search in sources :

Example 1 with ReactionDatabase

use of org.thoughtcrime.securesms.database.ReactionDatabase in project Signal-Android by WhisperSystems.

the class ReactionSendJob method onRun.

@Override
protected void onRun() throws Exception {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    ReactionDatabase reactionDatabase = SignalDatabase.reactions();
    MessageRecord message;
    if (messageId.isMms()) {
        message = SignalDatabase.mms().getMessageRecord(messageId.getId());
    } else {
        message = SignalDatabase.sms().getSmsMessage(messageId.getId());
    }
    Recipient targetAuthor = message.isOutgoing() ? Recipient.self() : message.getIndividualRecipient();
    long targetSentTimestamp = message.getDateSent();
    if (targetAuthor.getId().equals(SignalStore.releaseChannelValues().getReleaseChannelRecipientId())) {
        return;
    }
    if (!remove && !reactionDatabase.hasReaction(messageId, reaction)) {
        Log.w(TAG, "Went to add a reaction, but it's no longer present on the message!");
        return;
    }
    if (remove && reactionDatabase.hasReaction(messageId, reaction)) {
        Log.w(TAG, "Went to remove a reaction, but it's still there!");
        return;
    }
    Recipient conversationRecipient = SignalDatabase.threads().getRecipientForThreadId(message.getThreadId());
    if (conversationRecipient == null) {
        throw new AssertionError("We have a message, but couldn't find the thread!");
    }
    if (conversationRecipient.isPushV1Group() || conversationRecipient.isMmsGroup()) {
        Log.w(TAG, "Cannot send reactions to legacy groups.");
        return;
    }
    List<Recipient> resolved = recipients.stream().map(Recipient::resolved).collect(Collectors.toList());
    List<RecipientId> unregistered = resolved.stream().filter(Recipient::isUnregistered).map(Recipient::getId).collect(Collectors.toList());
    List<Recipient> destinations = resolved.stream().filter(Recipient::isMaybeRegistered).collect(Collectors.toList());
    List<Recipient> completions = deliver(conversationRecipient, destinations, targetAuthor, targetSentTimestamp);
    recipients.removeAll(unregistered);
    recipients.removeAll(completions.stream().map(Recipient::getId).collect(Collectors.toList()));
    Log.i(TAG, "Completed now: " + completions.size() + ", Remaining: " + recipients.size());
    if (!recipients.isEmpty()) {
        Log.w(TAG, "Still need to send to " + recipients.size() + " recipients. Retrying.");
        throw new RetryLaterException();
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) ReactionDatabase(org.thoughtcrime.securesms.database.ReactionDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException)

Example 2 with ReactionDatabase

use of org.thoughtcrime.securesms.database.ReactionDatabase in project Signal-Android by WhisperSystems.

the class ReactionSendJob method onFailure.

@Override
public void onFailure() {
    if (recipients.size() < initialRecipientCount) {
        Log.w(TAG, "Only sent a reaction to " + recipients.size() + "/" + initialRecipientCount + " recipients. Still, it sent to someone, so it stays.");
        return;
    }
    Log.w(TAG, "Failed to send the reaction to all recipients!");
    ReactionDatabase reactionDatabase = SignalDatabase.reactions();
    if (remove && !reactionDatabase.hasReaction(messageId, reaction)) {
        Log.w(TAG, "Reaction removal failed, so adding the reaction back.");
        reactionDatabase.addReaction(messageId, reaction);
    } else if (!remove && reactionDatabase.hasReaction(messageId, reaction)) {
        Log.w(TAG, "Reaction addition failed, so removing the reaction.");
        reactionDatabase.deleteReaction(messageId, reaction.getAuthor());
    } else {
        Log.w(TAG, "Reaction state didn't match what we'd expect to revert it, so we're just leaving it alone.");
    }
}
Also used : ReactionDatabase(org.thoughtcrime.securesms.database.ReactionDatabase)

Aggregations

ReactionDatabase (org.thoughtcrime.securesms.database.ReactionDatabase)2 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)1 NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)1 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)1