org.whispersystems.signalservice.api.messages.shared.SharedContact Java Examples

The following examples show how to use org.whispersystems.signalservice.api.messages.shared.SharedContact. 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: PushSendJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
List<SharedContact> getSharedContactsFor(OutgoingMediaMessage mediaMessage) {
  List<SharedContact> sharedContacts = new LinkedList<>();

  for (Contact contact : mediaMessage.getSharedContacts()) {
    SharedContact.Builder builder = ContactModelMapper.localToRemoteBuilder(contact);
    SharedContact.Avatar  avatar  = null;

    if (contact.getAvatar() != null && contact.getAvatar().getAttachment() != null) {
      avatar = SharedContact.Avatar.newBuilder().withAttachment(getAttachmentFor(contact.getAvatarAttachment()))
                                                .withProfileFlag(contact.getAvatar().isProfile())
                                                .build();
    }

    builder.setAvatar(avatar);
    sharedContacts.add(builder.build());
  }

  return sharedContacts;
}
 
Example #2
Source File: SignalServiceDataMessage.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Construct a SignalServiceDataMessage.
 *
 * @param timestamp The sent timestamp.
 * @param group The group information (or null if none).
 * @param attachments The attachments (or null if none).
 * @param body The message contents.
 * @param endSession Flag indicating whether this message should close a session.
 * @param expiresInSeconds Number of seconds in which the message should disappear after being seen.
 */
public SignalServiceDataMessage(long timestamp, SignalServiceGroup group,
                                List<SignalServiceAttachment> attachments,
                                String body, boolean endSession, int expiresInSeconds,
                                boolean expirationUpdate, byte[] profileKey, boolean profileKeyUpdate,
                                Quote quote, List<SharedContact> sharedContacts, List<Preview> previews,
                                Sticker sticker, boolean viewOnce)
{
  this.timestamp             = timestamp;
  this.body                  = Optional.fromNullable(body);
  this.group                 = Optional.fromNullable(group);
  this.endSession            = endSession;
  this.expiresInSeconds      = expiresInSeconds;
  this.expirationUpdate      = expirationUpdate;
  this.profileKey            = Optional.fromNullable(profileKey);
  this.profileKeyUpdate      = profileKeyUpdate;
  this.quote                 = Optional.fromNullable(quote);
  this.sticker               = Optional.fromNullable(sticker);
  this.viewOnce              = viewOnce;

  if (attachments != null && !attachments.isEmpty()) {
    this.attachments = Optional.of(attachments);
  } else {
    this.attachments = Optional.absent();
  }

  if (sharedContacts != null && !sharedContacts.isEmpty()) {
    this.contacts = Optional.of(sharedContacts);
  } else {
    this.contacts = Optional.absent();
  }

  if (previews != null && !previews.isEmpty()) {
    this.previews = Optional.of(previews);
  } else {
    this.previews = Optional.absent();
  }
}
 
Example #3
Source File: PushProcessMessageJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static Optional<List<Contact>> getContacts(Optional<List<SharedContact>> sharedContacts) {
  if (!sharedContacts.isPresent()) return Optional.absent();

  List<Contact> contacts = new ArrayList<>(sharedContacts.get().size());

  for (SharedContact sharedContact : sharedContacts.get()) {
    contacts.add(ContactModelMapper.remoteToLocal(sharedContact));
  }

  return Optional.of(contacts);
}
 
Example #4
Source File: ContactModelMapper.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static Phone.Type remoteToLocalType(SharedContact.Phone.Type type) {
  switch (type) {
    case HOME:   return Phone.Type.HOME;
    case MOBILE: return Phone.Type.MOBILE;
    case WORK:   return Phone.Type.WORK;
    default:     return Phone.Type.CUSTOM;
  }
}
 
Example #5
Source File: ContactModelMapper.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static Email.Type remoteToLocalType(SharedContact.Email.Type type) {
  switch (type) {
    case HOME:   return Email.Type.HOME;
    case MOBILE: return Email.Type.MOBILE;
    case WORK:   return Email.Type.WORK;
    default:     return Email.Type.CUSTOM;
  }
}
 
Example #6
Source File: ContactModelMapper.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static PostalAddress.Type remoteToLocalType(SharedContact.PostalAddress.Type type) {
  switch (type) {
    case HOME:   return PostalAddress.Type.HOME;
    case WORK:   return PostalAddress.Type.WORK;
    default:     return PostalAddress.Type.CUSTOM;
  }
}
 
Example #7
Source File: ContactModelMapper.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static SharedContact.Phone.Type localToRemoteType(Phone.Type type) {
  switch (type) {
    case HOME:   return SharedContact.Phone.Type.HOME;
    case MOBILE: return SharedContact.Phone.Type.MOBILE;
    case WORK:   return SharedContact.Phone.Type.WORK;
    default:     return SharedContact.Phone.Type.CUSTOM;
  }
}
 
Example #8
Source File: ContactModelMapper.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static SharedContact.Email.Type localToRemoteType(Email.Type type) {
  switch (type) {
    case HOME:   return SharedContact.Email.Type.HOME;
    case MOBILE: return SharedContact.Email.Type.MOBILE;
    case WORK:   return SharedContact.Email.Type.WORK;
    default:     return SharedContact.Email.Type.CUSTOM;
  }
}
 
Example #9
Source File: ContactModelMapper.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static SharedContact.PostalAddress.Type localToRemoteType(PostalAddress.Type type) {
  switch (type) {
    case HOME: return SharedContact.PostalAddress.Type.HOME;
    case WORK: return SharedContact.PostalAddress.Type.WORK;
    default:   return SharedContact.PostalAddress.Type.CUSTOM;
  }
}
 
Example #10
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());
}
 
Example #11
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private List<DataMessage.Contact> createSharedContactContent(List<SharedContact> contacts) throws IOException {
  List<DataMessage.Contact> results = new LinkedList<>();

  for (SharedContact contact : contacts) {
    DataMessage.Contact.Name.Builder nameBuilder    = DataMessage.Contact.Name.newBuilder();

    if (contact.getName().getFamily().isPresent())  nameBuilder.setFamilyName(contact.getName().getFamily().get());
    if (contact.getName().getGiven().isPresent())   nameBuilder.setGivenName(contact.getName().getGiven().get());
    if (contact.getName().getMiddle().isPresent())  nameBuilder.setMiddleName(contact.getName().getMiddle().get());
    if (contact.getName().getPrefix().isPresent())  nameBuilder.setPrefix(contact.getName().getPrefix().get());
    if (contact.getName().getSuffix().isPresent())  nameBuilder.setSuffix(contact.getName().getSuffix().get());
    if (contact.getName().getDisplay().isPresent()) nameBuilder.setDisplayName(contact.getName().getDisplay().get());

    DataMessage.Contact.Builder contactBuilder = DataMessage.Contact.newBuilder()
                                                                    .setName(nameBuilder);

    if (contact.getAddress().isPresent()) {
      for (SharedContact.PostalAddress address : contact.getAddress().get()) {
        DataMessage.Contact.PostalAddress.Builder addressBuilder = DataMessage.Contact.PostalAddress.newBuilder();

        switch (address.getType()) {
          case HOME:   addressBuilder.setType(DataMessage.Contact.PostalAddress.Type.HOME); break;
          case WORK:   addressBuilder.setType(DataMessage.Contact.PostalAddress.Type.WORK); break;
          case CUSTOM: addressBuilder.setType(DataMessage.Contact.PostalAddress.Type.CUSTOM); break;
          default:     throw new AssertionError("Unknown type: " + address.getType());
        }

        if (address.getCity().isPresent())         addressBuilder.setCity(address.getCity().get());
        if (address.getCountry().isPresent())      addressBuilder.setCountry(address.getCountry().get());
        if (address.getLabel().isPresent())        addressBuilder.setLabel(address.getLabel().get());
        if (address.getNeighborhood().isPresent()) addressBuilder.setNeighborhood(address.getNeighborhood().get());
        if (address.getPobox().isPresent())        addressBuilder.setPobox(address.getPobox().get());
        if (address.getPostcode().isPresent())     addressBuilder.setPostcode(address.getPostcode().get());
        if (address.getRegion().isPresent())       addressBuilder.setRegion(address.getRegion().get());
        if (address.getStreet().isPresent())       addressBuilder.setStreet(address.getStreet().get());

        contactBuilder.addAddress(addressBuilder);
      }
    }

    if (contact.getEmail().isPresent()) {
      for (SharedContact.Email email : contact.getEmail().get()) {
        DataMessage.Contact.Email.Builder emailBuilder = DataMessage.Contact.Email.newBuilder()
                                                                                  .setValue(email.getValue());

        switch (email.getType()) {
          case HOME:   emailBuilder.setType(DataMessage.Contact.Email.Type.HOME);   break;
          case WORK:   emailBuilder.setType(DataMessage.Contact.Email.Type.WORK);   break;
          case MOBILE: emailBuilder.setType(DataMessage.Contact.Email.Type.MOBILE); break;
          case CUSTOM: emailBuilder.setType(DataMessage.Contact.Email.Type.CUSTOM); break;
          default:     throw new AssertionError("Unknown type: " + email.getType());
        }

        if (email.getLabel().isPresent()) emailBuilder.setLabel(email.getLabel().get());

        contactBuilder.addEmail(emailBuilder);
      }
    }

    if (contact.getPhone().isPresent()) {
      for (SharedContact.Phone phone : contact.getPhone().get()) {
        DataMessage.Contact.Phone.Builder phoneBuilder = DataMessage.Contact.Phone.newBuilder()
                                                                                  .setValue(phone.getValue());

        switch (phone.getType()) {
          case HOME:   phoneBuilder.setType(DataMessage.Contact.Phone.Type.HOME);   break;
          case WORK:   phoneBuilder.setType(DataMessage.Contact.Phone.Type.WORK);   break;
          case MOBILE: phoneBuilder.setType(DataMessage.Contact.Phone.Type.MOBILE); break;
          case CUSTOM: phoneBuilder.setType(DataMessage.Contact.Phone.Type.CUSTOM); break;
          default:     throw new AssertionError("Unknown type: " + phone.getType());
        }

        if (phone.getLabel().isPresent()) phoneBuilder.setLabel(phone.getLabel().get());

        contactBuilder.addNumber(phoneBuilder);
      }
    }

    if (contact.getAvatar().isPresent()) {
      AttachmentPointer pointer = contact.getAvatar().get().getAttachment().isStream() ? createAttachmentPointer(contact.getAvatar().get().getAttachment().asStream())
                                                                                       : createAttachmentPointer(contact.getAvatar().get().getAttachment().asPointer());
      contactBuilder.setAvatar(DataMessage.Contact.Avatar.newBuilder()
                                                         .setAvatar(pointer)
                                                         .setIsProfile(contact.getAvatar().get().isProfile()));
    }

    if (contact.getOrganization().isPresent()) {
      contactBuilder.setOrganization(contact.getOrganization().get());
    }

    results.add(contactBuilder.build());
  }

  return results;
}
 
Example #12
Source File: SignalServiceDataMessage.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public Builder withSharedContacts(List<SharedContact> contacts) {
  this.sharedContacts.addAll(contacts);
  return this;
}
 
Example #13
Source File: SignalServiceDataMessage.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public Builder withSharedContact(SharedContact contact) {
  this.sharedContacts.add(contact);
  return this;
}
 
Example #14
Source File: SignalServiceDataMessage.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public Optional<List<SharedContact>> getSharedContacts() {
  return contacts;
}
 
Example #15
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
private List<DataMessage.Contact> createSharedContactContent(List<SharedContact> contacts) throws IOException {
  List<DataMessage.Contact> results = new LinkedList<>();

  for (SharedContact contact : contacts) {
    DataMessage.Contact.Name.Builder nameBuilder    = DataMessage.Contact.Name.newBuilder();

    if (contact.getName().getFamily().isPresent())  nameBuilder.setFamilyName(contact.getName().getFamily().get());
    if (contact.getName().getGiven().isPresent())   nameBuilder.setGivenName(contact.getName().getGiven().get());
    if (contact.getName().getMiddle().isPresent())  nameBuilder.setMiddleName(contact.getName().getMiddle().get());
    if (contact.getName().getPrefix().isPresent())  nameBuilder.setPrefix(contact.getName().getPrefix().get());
    if (contact.getName().getSuffix().isPresent())  nameBuilder.setSuffix(contact.getName().getSuffix().get());
    if (contact.getName().getDisplay().isPresent()) nameBuilder.setDisplayName(contact.getName().getDisplay().get());

    DataMessage.Contact.Builder contactBuilder = DataMessage.Contact.newBuilder()
                                                                    .setName(nameBuilder);

    if (contact.getAddress().isPresent()) {
      for (SharedContact.PostalAddress address : contact.getAddress().get()) {
        DataMessage.Contact.PostalAddress.Builder addressBuilder = DataMessage.Contact.PostalAddress.newBuilder();

        switch (address.getType()) {
          case HOME:   addressBuilder.setType(DataMessage.Contact.PostalAddress.Type.HOME); break;
          case WORK:   addressBuilder.setType(DataMessage.Contact.PostalAddress.Type.WORK); break;
          case CUSTOM: addressBuilder.setType(DataMessage.Contact.PostalAddress.Type.CUSTOM); break;
          default:     throw new AssertionError("Unknown type: " + address.getType());
        }

        if (address.getCity().isPresent())         addressBuilder.setCity(address.getCity().get());
        if (address.getCountry().isPresent())      addressBuilder.setCountry(address.getCountry().get());
        if (address.getLabel().isPresent())        addressBuilder.setLabel(address.getLabel().get());
        if (address.getNeighborhood().isPresent()) addressBuilder.setNeighborhood(address.getNeighborhood().get());
        if (address.getPobox().isPresent())        addressBuilder.setPobox(address.getPobox().get());
        if (address.getPostcode().isPresent())     addressBuilder.setPostcode(address.getPostcode().get());
        if (address.getRegion().isPresent())       addressBuilder.setRegion(address.getRegion().get());
        if (address.getStreet().isPresent())       addressBuilder.setStreet(address.getStreet().get());

        contactBuilder.addAddress(addressBuilder);
      }
    }

    if (contact.getEmail().isPresent()) {
      for (SharedContact.Email email : contact.getEmail().get()) {
        DataMessage.Contact.Email.Builder emailBuilder = DataMessage.Contact.Email.newBuilder()
                                                                                  .setValue(email.getValue());

        switch (email.getType()) {
          case HOME:   emailBuilder.setType(DataMessage.Contact.Email.Type.HOME);   break;
          case WORK:   emailBuilder.setType(DataMessage.Contact.Email.Type.WORK);   break;
          case MOBILE: emailBuilder.setType(DataMessage.Contact.Email.Type.MOBILE); break;
          case CUSTOM: emailBuilder.setType(DataMessage.Contact.Email.Type.CUSTOM); break;
          default:     throw new AssertionError("Unknown type: " + email.getType());
        }

        if (email.getLabel().isPresent()) emailBuilder.setLabel(email.getLabel().get());

        contactBuilder.addEmail(emailBuilder);
      }
    }

    if (contact.getPhone().isPresent()) {
      for (SharedContact.Phone phone : contact.getPhone().get()) {
        DataMessage.Contact.Phone.Builder phoneBuilder = DataMessage.Contact.Phone.newBuilder()
                                                                                  .setValue(phone.getValue());

        switch (phone.getType()) {
          case HOME:   phoneBuilder.setType(DataMessage.Contact.Phone.Type.HOME);   break;
          case WORK:   phoneBuilder.setType(DataMessage.Contact.Phone.Type.WORK);   break;
          case MOBILE: phoneBuilder.setType(DataMessage.Contact.Phone.Type.MOBILE); break;
          case CUSTOM: phoneBuilder.setType(DataMessage.Contact.Phone.Type.CUSTOM); break;
          default:     throw new AssertionError("Unknown type: " + phone.getType());
        }

        if (phone.getLabel().isPresent()) phoneBuilder.setLabel(phone.getLabel().get());

        contactBuilder.addNumber(phoneBuilder);
      }
    }

    if (contact.getAvatar().isPresent()) {
      AttachmentPointer pointer = contact.getAvatar().get().getAttachment().isStream() ? createAttachmentPointer(contact.getAvatar().get().getAttachment().asStream())
                                                                                       : createAttachmentPointer(contact.getAvatar().get().getAttachment().asPointer());
      contactBuilder.setAvatar(DataMessage.Contact.Avatar.newBuilder()
                                                         .setAvatar(pointer)
                                                         .setIsProfile(contact.getAvatar().get().isProfile()));
    }

    if (contact.getOrganization().isPresent()) {
      contactBuilder.setOrganization(contact.getOrganization().get());
    }

    results.add(contactBuilder.build());
  }

  return results;
}
 
Example #16
Source File: ContactModelMapper.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static Contact remoteToLocal(@NonNull SharedContact sharedContact) {
  Name name = new Name(sharedContact.getName().getDisplay().orNull(),
      sharedContact.getName().getGiven().orNull(),
      sharedContact.getName().getFamily().orNull(),
      sharedContact.getName().getPrefix().orNull(),
      sharedContact.getName().getSuffix().orNull(),
      sharedContact.getName().getMiddle().orNull());

  List<Phone> phoneNumbers = new LinkedList<>();
  if (sharedContact.getPhone().isPresent()) {
    for (SharedContact.Phone phone : sharedContact.getPhone().get()) {
      phoneNumbers.add(new Phone(phone.getValue(),
                                 remoteToLocalType(phone.getType()),
                                 phone.getLabel().orNull()));
    }
  }

  List<Email> emails = new LinkedList<>();
  if (sharedContact.getEmail().isPresent()) {
    for (SharedContact.Email email : sharedContact.getEmail().get()) {
      emails.add(new Email(email.getValue(),
                           remoteToLocalType(email.getType()),
                           email.getLabel().orNull()));
    }
  }

  List<PostalAddress> postalAddresses = new LinkedList<>();
  if (sharedContact.getAddress().isPresent()) {
    for (SharedContact.PostalAddress postalAddress : sharedContact.getAddress().get()) {
      postalAddresses.add(new PostalAddress(remoteToLocalType(postalAddress.getType()),
                                            postalAddress.getLabel().orNull(),
                                            postalAddress.getStreet().orNull(),
                                            postalAddress.getPobox().orNull(),
                                            postalAddress.getNeighborhood().orNull(),
                                            postalAddress.getCity().orNull(),
                                            postalAddress.getRegion().orNull(),
                                            postalAddress.getPostcode().orNull(),
                                            postalAddress.getCountry().orNull()));
    }
  }

  Avatar avatar = null;
  if (sharedContact.getAvatar().isPresent()) {
    Attachment attachment = PointerAttachment.forPointer(Optional.of(sharedContact.getAvatar().get().getAttachment().asPointer())).get();
    boolean    isProfile  = sharedContact.getAvatar().get().isProfile();

    avatar = new Avatar(null, attachment, isProfile);
  }

  return new Contact(name, sharedContact.getOrganization().orNull(), phoneNumbers, emails, postalAddresses, avatar);
}
 
Example #17
Source File: ContactModelMapper.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static SharedContact.Builder localToRemoteBuilder(@NonNull Contact contact) {
  List<SharedContact.Phone>         phoneNumbers    = new ArrayList<>(contact.getPhoneNumbers().size());
  List<SharedContact.Email>         emails          = new ArrayList<>(contact.getEmails().size());
  List<SharedContact.PostalAddress> postalAddresses = new ArrayList<>(contact.getPostalAddresses().size());

  for (Phone phone : contact.getPhoneNumbers()) {
    phoneNumbers.add(new SharedContact.Phone.Builder().setValue(phone.getNumber())
                                                      .setType(localToRemoteType(phone.getType()))
                                                      .setLabel(phone.getLabel())
                                                      .build());
  }

  for (Email email : contact.getEmails()) {
    emails.add(new SharedContact.Email.Builder().setValue(email.getEmail())
                                                .setType(localToRemoteType(email.getType()))
                                                .setLabel(email.getLabel())
                                                .build());
  }

  for (PostalAddress postalAddress : contact.getPostalAddresses()) {
    postalAddresses.add(new SharedContact.PostalAddress.Builder().setType(localToRemoteType(postalAddress.getType()))
                                                                 .setLabel(postalAddress.getLabel())
                                                                 .setStreet(postalAddress.getStreet())
                                                                 .setPobox(postalAddress.getPoBox())
                                                                 .setNeighborhood(postalAddress.getNeighborhood())
                                                                 .setCity(postalAddress.getCity())
                                                                 .setRegion(postalAddress.getRegion())
                                                                 .setPostcode(postalAddress.getPostalCode())
                                                                 .setCountry(postalAddress.getCountry())
                                                                 .build());
  }

  SharedContact.Name name = new SharedContact.Name.Builder().setDisplay(contact.getName().getDisplayName())
                                                            .setGiven(contact.getName().getGivenName())
                                                            .setFamily(contact.getName().getFamilyName())
                                                            .setPrefix(contact.getName().getPrefix())
                                                            .setSuffix(contact.getName().getSuffix())
                                                            .setMiddle(contact.getName().getMiddleName())
                                                            .build();

  return new SharedContact.Builder().setName(name)
                                    .withOrganization(contact.getOrganization())
                                    .withPhones(phoneNumbers)
                                    .withEmails(emails)
                                    .withAddresses(postalAddresses);
}
 
Example #18
Source File: SignalServiceDataMessage.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public Builder withSharedContacts(List<SharedContact> contacts) {
  this.sharedContacts.addAll(contacts);
  return this;
}
 
Example #19
Source File: SignalServiceDataMessage.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public Builder withSharedContact(SharedContact contact) {
  this.sharedContacts.add(contact);
  return this;
}
 
Example #20
Source File: SignalServiceDataMessage.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public Optional<List<SharedContact>> getSharedContacts() {
  return contacts;
}
 
Example #21
Source File: SignalServiceDataMessage.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Construct a SignalServiceDataMessage.
 *
 * @param timestamp The sent timestamp.
 * @param group The group information (or null if none).
 * @param groupV2 The group information (or null if none).
 * @param attachments The attachments (or null if none).
 * @param body The message contents.
 * @param endSession Flag indicating whether this message should close a session.
 * @param expiresInSeconds Number of seconds in which the message should disappear after being seen.
 */
SignalServiceDataMessage(long timestamp,
                         SignalServiceGroup group, SignalServiceGroupV2 groupV2,
                         List<SignalServiceAttachment> attachments,
                         String body, boolean endSession, int expiresInSeconds,
                         boolean expirationUpdate, byte[] profileKey, boolean profileKeyUpdate,
                         Quote quote, List<SharedContact> sharedContacts, List<Preview> previews,
                         Sticker sticker, boolean viewOnce, Reaction reaction, RemoteDelete remoteDelete)
{
  try {
    this.group = SignalServiceGroupContext.createOptional(group, groupV2);
  } catch (InvalidMessageException e) {
    throw new AssertionError(e);
  }

  this.timestamp             = timestamp;
  this.body                  = OptionalUtil.absentIfEmpty(body);
  this.endSession            = endSession;
  this.expiresInSeconds      = expiresInSeconds;
  this.expirationUpdate      = expirationUpdate;
  this.profileKey            = Optional.fromNullable(profileKey);
  this.profileKeyUpdate      = profileKeyUpdate;
  this.quote                 = Optional.fromNullable(quote);
  this.sticker               = Optional.fromNullable(sticker);
  this.viewOnce              = viewOnce;
  this.reaction              = Optional.fromNullable(reaction);
  this.remoteDelete          = Optional.fromNullable(remoteDelete);

  if (attachments != null && !attachments.isEmpty()) {
    this.attachments = Optional.of(attachments);
  } else {
    this.attachments = Optional.absent();
  }

  if (sharedContacts != null && !sharedContacts.isEmpty()) {
    this.contacts = Optional.of(sharedContacts);
  } else {
    this.contacts = Optional.absent();
  }

  if (previews != null && !previews.isEmpty()) {
    this.previews = Optional.of(previews);
  } else {
    this.previews = Optional.absent();
  }
}
 
Example #22
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static SignalServiceDataMessage createSignalServiceMessage(SignalServiceMetadata metadata,
                                                                   SignalServiceProtos.DataMessage content)
    throws ProtocolInvalidMessageException, UnsupportedDataMessageException
{
  SignalServiceGroup                  groupInfoV1  = createGroupV1Info(content);
  SignalServiceGroupV2                groupInfoV2  = createGroupV2Info(content);
  Optional<SignalServiceGroupContext> groupContext;

  try {
    groupContext = SignalServiceGroupContext.createOptional(groupInfoV1, groupInfoV2);
  } catch (InvalidMessageException e) {
    throw new ProtocolInvalidMessageException(e, null, 0);
  }


  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);
  SignalServiceDataMessage.Quote         quote            = createQuote(content);
  List<SharedContact>                    sharedContacts   = createSharedContacts(content);
  List<SignalServiceDataMessage.Preview> previews         = createPreviews(content);
  SignalServiceDataMessage.Sticker       sticker          = createSticker(content);
  SignalServiceDataMessage.Reaction      reaction         = createReaction(content);
  SignalServiceDataMessage.RemoteDelete  remoteDelete     = createRemoteDelete(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);
  }

  for (SignalServiceProtos.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(),
                                      groupInfoV1, groupInfoV2,
                                      attachments,
                                      content.hasBody() ? content.getBody() : null,
                                      endSession,
                                      content.getExpireTimer(),
                                      expirationUpdate,
                                      content.hasProfileKey() ? content.getProfileKey().toByteArray() : null,
                                      profileKeyUpdate,
                                      quote,
                                      sharedContacts,
                                      previews,
                                      sticker,
                                      content.getIsViewOnce(),
                                      reaction,
                                      remoteDelete);
}