Search in sources :

Example 61 with SignalServiceAddress

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

the class SignalServiceAddressProtobufSerializer method fromProtobuf.

public static SignalServiceAddress fromProtobuf(AddressProto addressProto) {
    ServiceId serviceId = ServiceId.parseOrThrow(addressProto.getUuid().toByteArray());
    Optional<String> number = addressProto.hasE164() ? Optional.of(addressProto.getE164()) : Optional.absent();
    return new SignalServiceAddress(serviceId, number);
}
Also used : SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ServiceId(org.whispersystems.signalservice.api.push.ServiceId)

Example 62 with SignalServiceAddress

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

the class SignalServiceMessageReceiver method retrieveMessages.

public List<SignalServiceEnvelope> retrieveMessages(MessageReceivedCallback callback) throws IOException {
    List<SignalServiceEnvelope> results = new LinkedList<>();
    SignalServiceMessagesResult messageResult = socket.getMessages();
    for (SignalServiceEnvelopeEntity entity : messageResult.getEnvelopes()) {
        SignalServiceEnvelope envelope;
        if (entity.hasSource() && entity.getSourceDevice() > 0) {
            SignalServiceAddress address = new SignalServiceAddress(ACI.parseOrThrow(entity.getSourceUuid()), entity.getSourceE164());
            envelope = new SignalServiceEnvelope(entity.getType(), Optional.of(address), entity.getSourceDevice(), entity.getTimestamp(), entity.getMessage(), entity.getContent(), entity.getServerTimestamp(), messageResult.getServerDeliveredTimestamp(), entity.getServerUuid());
        } else {
            envelope = new SignalServiceEnvelope(entity.getType(), entity.getTimestamp(), entity.getMessage(), entity.getContent(), entity.getServerTimestamp(), messageResult.getServerDeliveredTimestamp(), entity.getServerUuid());
        }
        callback.onMessage(envelope);
        results.add(envelope);
        if (envelope.hasServerGuid()) {
            socket.acknowledgeMessage(envelope.getServerGuid());
        } else {
            socket.acknowledgeMessage(entity.getSourceE164(), entity.getTimestamp());
        }
    }
    return results;
}
Also used : SignalServiceEnvelopeEntity(org.whispersystems.signalservice.internal.push.SignalServiceEnvelopeEntity) SignalServiceMessagesResult(org.whispersystems.signalservice.internal.push.SignalServiceMessagesResult) SignalServiceEnvelope(org.whispersystems.signalservice.api.messages.SignalServiceEnvelope) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) LinkedList(java.util.LinkedList)

Aggregations

SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)62 Recipient (org.thoughtcrime.securesms.recipients.Recipient)22 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)18 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)17 LinkedList (java.util.LinkedList)13 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)13 Optional (org.whispersystems.libsignal.util.guava.Optional)11 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)11 IOException (java.io.IOException)10 NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)10 UnidentifiedAccessPair (org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair)10 NonNull (androidx.annotation.NonNull)9 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)8 UnregisteredUserException (org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException)8 List (java.util.List)7 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)7 Nullable (androidx.annotation.Nullable)6 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)6 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)6 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)6