Java Code Examples for org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage#getFlags()

The following examples show how to use org.whispersystems.signalservice.internal.push.SignalServiceProtos.DataMessage#getFlags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignalServiceCipher.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private SignalServiceDataMessage createSignalServiceMessage(SignalServiceProtos.Envelope envelope, DataMessage content) throws InvalidMessageException {
  SignalServiceGroup            groupInfo        = createGroupInfo(envelope, content);
  List<SignalServiceAttachment> attachments      = new LinkedList<>();
  boolean                       endSession       = ((content.getFlags() & DataMessage.Flags.END_SESSION_VALUE) != 0);
  boolean                       expirationUpdate = ((content.getFlags() & DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0);
  boolean                       profileKeyUpdate = ((content.getFlags() & DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE) != 0);
    boolean newGroupShare = ((content.getFlags() & 8) != 0);//添加 newGroupShare 类型

  for (AttachmentPointer pointer : content.getAttachmentsList()) {
    attachments.add(new SignalServiceAttachmentPointer(pointer.getId(),
                                                       pointer.getContentType(),
                                                       pointer.getKey().toByteArray(),
                                                       envelope.getRelay(),
                                                       pointer.hasSize() ? Optional.of(pointer.getSize()) : Optional.<Integer>absent(),
                                                       pointer.hasThumbnail() ? Optional.of(pointer.getThumbnail().toByteArray()): Optional.<byte[]>absent(),
                                                       pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.<byte[]>absent(),
                                                       pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.<String>absent(),
                                                       (pointer.getFlags() & AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) != 0,
                                                       pointer.hasUrl() ? Optional.of(pointer.getUrl()) : Optional.<String>absent()));
  }

  if (content.hasTimestamp() && content.getTimestamp() != envelope.getTimestamp()) {
    throw new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + envelope.getTimestamp());
  }

  return new SignalServiceDataMessage(envelope.getTimestamp(), groupInfo, attachments,
                                      content.getBody(), endSession, content.getExpireTimer(),
                                      expirationUpdate, content.hasProfileKey() ? content.getProfileKey().toByteArray() : null,
          profileKeyUpdate, newGroupShare);
}
 
Example 2
Source File: SignalServiceCipher.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
private SignalServiceDataMessage createSignalServiceMessage(Metadata metadata, DataMessage content)
    throws ProtocolInvalidMessageException, UnsupportedDataMessageException
{
  SignalServiceGroup             groupInfo        = createGroupInfo(content);
  List<SignalServiceAttachment>  attachments      = new LinkedList<>();
  boolean                        endSession       = ((content.getFlags() & DataMessage.Flags.END_SESSION_VALUE            ) != 0);
  boolean                        expirationUpdate = ((content.getFlags() & DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE) != 0);
  boolean                        profileKeyUpdate = ((content.getFlags() & DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE     ) != 0);
  SignalServiceDataMessage.Quote quote            = createQuote(content);
  List<SharedContact>            sharedContacts   = createSharedContacts(content);
  List<Preview>                  previews         = createPreviews(content);
  Sticker                        sticker          = createSticker(content);

  if (content.getRequiredProtocolVersion() > DataMessage.ProtocolVersion.CURRENT.getNumber()) {
    throw new UnsupportedDataMessageException(DataMessage.ProtocolVersion.CURRENT.getNumber(),
                                              content.getRequiredProtocolVersion(),
                                              metadata.getSender().getIdentifier(),
                                              metadata.getSenderDevice(),
                                              Optional.fromNullable(groupInfo));
  }

  for (AttachmentPointer pointer : content.getAttachmentsList()) {
    attachments.add(createAttachmentPointer(pointer));
  }

  if (content.hasTimestamp() && content.getTimestamp() != metadata.getTimestamp()) {
    throw new ProtocolInvalidMessageException(new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + metadata.getTimestamp()),
                                                                          metadata.getSender().getIdentifier(),
                                                                          metadata.getSenderDevice());
  }

  return new SignalServiceDataMessage(metadata.getTimestamp(),
                                      groupInfo,
                                      attachments,
                                      content.getBody(),
                                      endSession,
                                      content.getExpireTimer(),
                                      expirationUpdate,
                                      content.hasProfileKey() ? content.getProfileKey().toByteArray() : null,
                                      profileKeyUpdate,
                                      quote,
                                      sharedContacts,
                                      previews,
                                      sticker,
                                      content.getIsViewOnce());
}