Search in sources :

Example 1 with SyncMessage

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

the class SignalServiceCipher method createSynchronizeMessage.

private SignalServiceSyncMessage createSynchronizeMessage(SignalServiceEnvelope envelope, SyncMessage content) throws InvalidMessageException {
    if (content.hasSent()) {
        SyncMessage.Sent sentContent = content.getSent();
        return SignalServiceSyncMessage.forSentTranscript(new SentTranscriptMessage(sentContent.getDestination(), sentContent.getTimestamp(), createSignalServiceMessage(envelope, sentContent.getMessage()), sentContent.getExpirationStartTimestamp()));
    }
    if (content.hasRequest()) {
        return SignalServiceSyncMessage.forRequest(new RequestMessage(content.getRequest()));
    }
    if (content.getReadList().size() > 0) {
        List<ReadMessage> readMessages = new LinkedList<>();
        for (SyncMessage.Read read : content.getReadList()) {
            readMessages.add(new ReadMessage(read.getSender(), read.getTimestamp()));
        }
        return SignalServiceSyncMessage.forRead(readMessages);
    }
    if (content.hasVerified()) {
        try {
            Verified verified = content.getVerified();
            String destination = verified.getDestination();
            IdentityKey identityKey = new IdentityKey(verified.getIdentityKey().toByteArray(), 0);
            VerifiedState verifiedState;
            if (verified.getState() == Verified.State.DEFAULT) {
                verifiedState = VerifiedState.DEFAULT;
            } else if (verified.getState() == Verified.State.VERIFIED) {
                verifiedState = VerifiedState.VERIFIED;
            } else if (verified.getState() == Verified.State.UNVERIFIED) {
                verifiedState = VerifiedState.UNVERIFIED;
            } else {
                throw new InvalidMessageException("Unknown state: " + verified.getState().getNumber());
            }
            return SignalServiceSyncMessage.forVerified(new VerifiedMessage(destination, identityKey, verifiedState, System.currentTimeMillis()));
        } catch (InvalidKeyException e) {
            throw new InvalidMessageException(e);
        }
    }
    return SignalServiceSyncMessage.empty();
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) IdentityKey(org.whispersystems.libsignal.IdentityKey) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) LinkedList(java.util.LinkedList) SyncMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) Verified(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Verified) ReadMessage(org.whispersystems.signalservice.api.messages.multidevice.ReadMessage) RequestMessage(org.whispersystems.signalservice.api.messages.multidevice.RequestMessage) VerifiedState(org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage.VerifiedState) SentTranscriptMessage(org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage) VerifiedMessage(org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)

Example 2 with SyncMessage

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

the class SignalServiceMessageSender method createMultiDeviceSentTranscriptContent.

private byte[] createMultiDeviceSentTranscriptContent(byte[] content, Optional<SignalServiceAddress> recipient, long timestamp) {
    try {
        Content.Builder container = Content.newBuilder();
        SyncMessage.Builder syncMessage = createSyncMessageBuilder();
        SyncMessage.Sent.Builder sentMessage = SyncMessage.Sent.newBuilder();
        DataMessage dataMessage = Content.parseFrom(content).getDataMessage();
        sentMessage.setTimestamp(timestamp);
        sentMessage.setMessage(dataMessage);
        if (recipient.isPresent()) {
            sentMessage.setDestination(recipient.get().getNumber());
        }
        if (dataMessage.getExpireTimer() > 0) {
            sentMessage.setExpirationStartTimestamp(System.currentTimeMillis());
        }
        return container.setSyncMessage(syncMessage.setSent(sentMessage)).build().toByteArray();
    } catch (InvalidProtocolBufferException e) {
        throw new AssertionError(e);
    }
}
Also used : SyncMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) DataMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Aggregations

SignalServiceSyncMessage (org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage)2 SyncMessage (org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 LinkedList (java.util.LinkedList)1 IdentityKey (org.whispersystems.libsignal.IdentityKey)1 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)1 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)1 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)1 ReadMessage (org.whispersystems.signalservice.api.messages.multidevice.ReadMessage)1 RequestMessage (org.whispersystems.signalservice.api.messages.multidevice.RequestMessage)1 SentTranscriptMessage (org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage)1 VerifiedMessage (org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)1 VerifiedState (org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage.VerifiedState)1 Content (org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content)1 DataMessage (org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage)1 Verified (org.whispersystems.signalservice.internal.push.SignalServiceProtos.Verified)1