Search in sources :

Example 1 with NetworkFailureException

use of org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException in project Signal-Android by WhisperSystems.

the class PushGroupSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws MmsException, IOException, NoSuchMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        deliver(masterSecret, message, filterRecipientId);
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message.getAttachments());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (InvalidNumberException | RecipientFormattingException | UndeliverableMessageException e) {
        Log.w(TAG, e);
        database.markAsSentFailed(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
    } catch (EncapsulatedExceptions e) {
        Log.w(TAG, e);
        List<NetworkFailure> failures = new LinkedList<>();
        for (NetworkFailureException nfe : e.getNetworkExceptions()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, nfe.getE164number(), false).getPrimaryRecipient();
            failures.add(new NetworkFailure(recipient.getRecipientId()));
        }
        for (UntrustedIdentityException uie : e.getUntrustedIdentityExceptions()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, uie.getE164Number(), false).getPrimaryRecipient();
            database.addMismatchedIdentity(messageId, recipient.getRecipientId(), uie.getIdentityKey());
        }
        database.addFailures(messageId, failures);
        if (e.getNetworkExceptions().isEmpty() && e.getUntrustedIdentityExceptions().isEmpty()) {
            database.markAsSent(messageId, true);
            markAttachmentsUploaded(messageId, message.getAttachments());
        } else {
            database.markAsSentFailed(messageId);
            notifyMediaMessageDeliveryFailed(context, messageId);
        }
    }
}
Also used : EncapsulatedExceptions(org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NetworkFailure(org.thoughtcrime.securesms.database.documents.NetworkFailure) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) LinkedList(java.util.LinkedList) List(java.util.List) NetworkFailureException(org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Aggregations

LinkedList (java.util.LinkedList)1 List (java.util.List)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 NetworkFailure (org.thoughtcrime.securesms.database.documents.NetworkFailure)1 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)1 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)1 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)1 EncapsulatedExceptions (org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions)1 NetworkFailureException (org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException)1 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)1