use of org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions in project Signal-Android by signalapp.
the class PushGroupSendJob method onPushSend.
@Override
public void onPushSend() throws MmsException, IOException, NoSuchMessageException {
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
try {
deliver(message, filterAddress == null ? null : Address.fromSerialized(filterAddress));
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()) {
failures.add(new NetworkFailure(Address.fromSerialized(nfe.getE164number())));
}
for (UntrustedIdentityException uie : e.getUntrustedIdentityExceptions()) {
database.addMismatchedIdentity(messageId, Address.fromSerialized(uie.getE164Number()), 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);
}
}
}
use of org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions in project libsignal-service-java by signalapp.
the class SignalServiceMessageSender method sendMessage.
/**
* Send a message to a group.
*
* @param recipients The group members.
* @param message The group message.
* @throws IOException
* @throws EncapsulatedExceptions
*/
public void sendMessage(List<SignalServiceAddress> recipients, SignalServiceDataMessage message) throws IOException, EncapsulatedExceptions {
byte[] content = createMessageContent(message);
long timestamp = message.getTimestamp();
SendMessageResponseList response = sendMessage(recipients, timestamp, content);
try {
if (response.getNeedsSync()) {
byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.<SignalServiceAddress>absent(), timestamp);
sendMessage(localAddress, timestamp, syncMessage, false);
}
} catch (UntrustedIdentityException e) {
response.addException(e);
}
if (response.hasExceptions()) {
throw new EncapsulatedExceptions(response.getUntrustedIdentities(), response.getUnregisteredUsers(), response.getNetworkExceptions());
}
}
use of org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions 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);
}
}
}
Aggregations