Search in sources :

Example 1 with UnsupportedDataMessageProtocolVersionException

use of org.whispersystems.signalservice.internal.push.UnsupportedDataMessageProtocolVersionException in project Signal-Android by WhisperSystems.

the class SignalServiceContent method createSignalServiceMessage.

private static SignalServiceDataMessage createSignalServiceMessage(SignalServiceMetadata metadata, SignalServiceProtos.DataMessage content) throws UnsupportedDataMessageException, InvalidMessageStructureException {
    SignalServiceGroupV2 groupInfoV2 = createGroupV2Info(content);
    Optional<SignalServiceGroupContext> groupContext;
    try {
        groupContext = SignalServiceGroupContext.createOptional(null, groupInfoV2);
    } catch (InvalidMessageException e) {
        throw new InvalidMessageStructureException(e);
    }
    List<SignalServiceAttachment> attachments = new LinkedList<>();
    boolean endSession = ((content.getFlags() & SignalServiceProtos.DataMessage.Flags.END_SESSION_VALUE) != 0);
    boolean expirationUpdate = ((content.getFlags() & SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0);
    boolean profileKeyUpdate = ((content.getFlags() & SignalServiceProtos.DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE) != 0);
    boolean isGroupV2 = groupInfoV2 != null;
    SignalServiceDataMessage.Quote quote = createQuote(content, isGroupV2);
    List<SharedContact> sharedContacts = createSharedContacts(content);
    List<SignalServiceDataMessage.Preview> previews = createPreviews(content);
    List<SignalServiceDataMessage.Mention> mentions = createMentions(content.getBodyRangesList(), content.getBody(), isGroupV2);
    SignalServiceDataMessage.Sticker sticker = createSticker(content);
    SignalServiceDataMessage.Reaction reaction = createReaction(content);
    SignalServiceDataMessage.RemoteDelete remoteDelete = createRemoteDelete(content);
    SignalServiceDataMessage.GroupCallUpdate groupCallUpdate = createGroupCallUpdate(content);
    SignalServiceDataMessage.StoryContext storyContext = createStoryContext(content);
    if (content.getRequiredProtocolVersion() > SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT_VALUE) {
        throw new UnsupportedDataMessageProtocolVersionException(SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT_VALUE, content.getRequiredProtocolVersion(), metadata.getSender().getIdentifier(), metadata.getSenderDevice(), groupContext);
    }
    SignalServiceDataMessage.Payment payment = createPayment(content);
    if (content.getRequiredProtocolVersion() > SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT.getNumber()) {
        throw new UnsupportedDataMessageProtocolVersionException(SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT.getNumber(), content.getRequiredProtocolVersion(), metadata.getSender().getIdentifier(), metadata.getSenderDevice(), groupContext);
    }
    for (SignalServiceProtos.AttachmentPointer pointer : content.getAttachmentsList()) {
        attachments.add(createAttachmentPointer(pointer));
    }
    if (content.hasTimestamp() && content.getTimestamp() != metadata.getTimestamp()) {
        throw new InvalidMessageStructureException("Timestamps don't match: " + content.getTimestamp() + " vs " + metadata.getTimestamp(), metadata.getSender().getIdentifier(), metadata.getSenderDevice());
    }
    return new SignalServiceDataMessage(metadata.getTimestamp(), null, groupInfoV2, attachments, content.hasBody() ? content.getBody() : null, endSession, content.getExpireTimer(), expirationUpdate, content.hasProfileKey() ? content.getProfileKey().toByteArray() : null, profileKeyUpdate, quote, sharedContacts, previews, mentions, sticker, content.getIsViewOnce(), reaction, remoteDelete, groupCallUpdate, payment, storyContext);
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) ProtocolInvalidMessageException(org.signal.libsignal.metadata.ProtocolInvalidMessageException) InvalidMessageStructureException(org.whispersystems.signalservice.api.InvalidMessageStructureException) LinkedList(java.util.LinkedList) UnsupportedDataMessageProtocolVersionException(org.whispersystems.signalservice.internal.push.UnsupportedDataMessageProtocolVersionException) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact)

Example 2 with UnsupportedDataMessageProtocolVersionException

use of org.whispersystems.signalservice.internal.push.UnsupportedDataMessageProtocolVersionException in project Signal-Android by signalapp.

the class SignalServiceContent method createSignalServiceMessage.

private static SignalServiceDataMessage createSignalServiceMessage(SignalServiceMetadata metadata, SignalServiceProtos.DataMessage content) throws UnsupportedDataMessageException, InvalidMessageStructureException {
    SignalServiceGroupV2 groupInfoV2 = createGroupV2Info(content);
    Optional<SignalServiceGroupContext> groupContext;
    try {
        groupContext = SignalServiceGroupContext.createOptional(null, groupInfoV2);
    } catch (InvalidMessageException e) {
        throw new InvalidMessageStructureException(e);
    }
    List<SignalServiceAttachment> attachments = new LinkedList<>();
    boolean endSession = ((content.getFlags() & SignalServiceProtos.DataMessage.Flags.END_SESSION_VALUE) != 0);
    boolean expirationUpdate = ((content.getFlags() & SignalServiceProtos.DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0);
    boolean profileKeyUpdate = ((content.getFlags() & SignalServiceProtos.DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE) != 0);
    boolean isGroupV2 = groupInfoV2 != null;
    SignalServiceDataMessage.Quote quote = createQuote(content, isGroupV2);
    List<SharedContact> sharedContacts = createSharedContacts(content);
    List<SignalServiceDataMessage.Preview> previews = createPreviews(content);
    List<SignalServiceDataMessage.Mention> mentions = createMentions(content.getBodyRangesList(), content.getBody(), isGroupV2);
    SignalServiceDataMessage.Sticker sticker = createSticker(content);
    SignalServiceDataMessage.Reaction reaction = createReaction(content);
    SignalServiceDataMessage.RemoteDelete remoteDelete = createRemoteDelete(content);
    SignalServiceDataMessage.GroupCallUpdate groupCallUpdate = createGroupCallUpdate(content);
    SignalServiceDataMessage.StoryContext storyContext = createStoryContext(content);
    if (content.getRequiredProtocolVersion() > SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT_VALUE) {
        throw new UnsupportedDataMessageProtocolVersionException(SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT_VALUE, content.getRequiredProtocolVersion(), metadata.getSender().getIdentifier(), metadata.getSenderDevice(), groupContext);
    }
    SignalServiceDataMessage.Payment payment = createPayment(content);
    if (content.getRequiredProtocolVersion() > SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT.getNumber()) {
        throw new UnsupportedDataMessageProtocolVersionException(SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT.getNumber(), content.getRequiredProtocolVersion(), metadata.getSender().getIdentifier(), metadata.getSenderDevice(), groupContext);
    }
    for (SignalServiceProtos.AttachmentPointer pointer : content.getAttachmentsList()) {
        attachments.add(createAttachmentPointer(pointer));
    }
    if (content.hasTimestamp() && content.getTimestamp() != metadata.getTimestamp()) {
        throw new InvalidMessageStructureException("Timestamps don't match: " + content.getTimestamp() + " vs " + metadata.getTimestamp(), metadata.getSender().getIdentifier(), metadata.getSenderDevice());
    }
    return new SignalServiceDataMessage(metadata.getTimestamp(), null, groupInfoV2, attachments, content.hasBody() ? content.getBody() : null, endSession, content.getExpireTimer(), expirationUpdate, content.hasProfileKey() ? content.getProfileKey().toByteArray() : null, profileKeyUpdate, quote, sharedContacts, previews, mentions, sticker, content.getIsViewOnce(), reaction, remoteDelete, groupCallUpdate, payment, storyContext);
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) ProtocolInvalidMessageException(org.signal.libsignal.metadata.ProtocolInvalidMessageException) InvalidMessageStructureException(org.whispersystems.signalservice.api.InvalidMessageStructureException) LinkedList(java.util.LinkedList) UnsupportedDataMessageProtocolVersionException(org.whispersystems.signalservice.internal.push.UnsupportedDataMessageProtocolVersionException) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact)

Aggregations

LinkedList (java.util.LinkedList)2 ProtocolInvalidMessageException (org.signal.libsignal.metadata.ProtocolInvalidMessageException)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 InvalidMessageStructureException (org.whispersystems.signalservice.api.InvalidMessageStructureException)2 SharedContact (org.whispersystems.signalservice.api.messages.shared.SharedContact)2 SignalServiceProtos (org.whispersystems.signalservice.internal.push.SignalServiceProtos)2 UnsupportedDataMessageProtocolVersionException (org.whispersystems.signalservice.internal.push.UnsupportedDataMessageProtocolVersionException)2