Search in sources :

Example 1 with SentTranscriptMessage

use of org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage 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)

Aggregations

LinkedList (java.util.LinkedList)1 IdentityKey (org.whispersystems.libsignal.IdentityKey)1 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)1 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)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 SignalServiceSyncMessage (org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage)1 VerifiedMessage (org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)1 VerifiedState (org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage.VerifiedState)1 SyncMessage (org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage)1 Verified (org.whispersystems.signalservice.internal.push.SignalServiceProtos.Verified)1