Search in sources :

Example 1 with SendMessageResponseList

use of org.whispersystems.signalservice.internal.push.SendMessageResponseList 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());
    }
}
Also used : EncapsulatedExceptions(org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions) SendMessageResponseList(org.whispersystems.signalservice.internal.push.SendMessageResponseList) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)

Example 2 with SendMessageResponseList

use of org.whispersystems.signalservice.internal.push.SendMessageResponseList in project libsignal-service-java by signalapp.

the class SignalServiceMessageSender method sendMessage.

private SendMessageResponseList sendMessage(List<SignalServiceAddress> recipients, long timestamp, byte[] content) throws IOException {
    SendMessageResponseList responseList = new SendMessageResponseList();
    for (SignalServiceAddress recipient : recipients) {
        try {
            SendMessageResponse response = sendMessage(recipient, timestamp, content, false);
            responseList.addResponse(response);
        } catch (UntrustedIdentityException e) {
            Log.w(TAG, e);
            responseList.addException(e);
        } catch (UnregisteredUserException e) {
            Log.w(TAG, e);
            responseList.addException(e);
        } catch (PushNetworkException e) {
            Log.w(TAG, e);
            responseList.addException(new NetworkFailureException(recipient.getNumber(), e));
        }
    }
    return responseList;
}
Also used : SendMessageResponse(org.whispersystems.signalservice.internal.push.SendMessageResponse) SendMessageResponseList(org.whispersystems.signalservice.internal.push.SendMessageResponseList) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) NetworkFailureException(org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException)

Aggregations

UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2 SendMessageResponseList (org.whispersystems.signalservice.internal.push.SendMessageResponseList)2 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)1 EncapsulatedExceptions (org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions)1 NetworkFailureException (org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException)1 PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)1 UnregisteredUserException (org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException)1 SendMessageResponse (org.whispersystems.signalservice.internal.push.SendMessageResponse)1