org.whispersystems.signalservice.api.util.UuidUtil Java Examples

The following examples show how to use org.whispersystems.signalservice.api.util.UuidUtil. 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: RecipientStore.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Set<SignalServiceAddress> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    JsonNode node = jsonParser.getCodec().readTree(jsonParser);

    Set<SignalServiceAddress> addresses = new HashSet<>();

    if (node.isArray()) {
        for (JsonNode recipient : node) {
            String recipientName = recipient.get("name").asText();
            UUID uuid = UuidUtil.parseOrThrow(recipient.get("uuid").asText());
            final SignalServiceAddress serviceAddress = new SignalServiceAddress(uuid, recipientName);
            addresses.add(serviceAddress);
        }
    }

    return addresses;
}
 
Example #2
Source File: GroupDatabase.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static String serializeV2GroupMembers(@NonNull DecryptedGroup decryptedGroup) {
  List<RecipientId> groupMembers  = new ArrayList<>(decryptedGroup.getMembersCount());

  for (DecryptedMember member : decryptedGroup.getMembersList()) {
    UUID uuid = UuidUtil.fromByteString(member.getUuid());
    if (UuidUtil.UNKNOWN_UUID.equals(uuid)) {
      Log.w(TAG, "Seen unknown UUID in members list");
    } else {
      groupMembers.add(RecipientId.from(uuid, null));
    }
  }

  Collections.sort(groupMembers);

  return RecipientId.toSerializedList(groupMembers);
}
 
Example #3
Source File: Recipient.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A safety wrapper around {@link #external(Context, String)} for when you know you're using an
 * identifier for a system contact, and therefore always want to prevent interpreting it as a
 * UUID. This will crash if given a UUID.
 *
 * (This may seem strange, but apparently some devices are returning valid UUIDs for contacts)
 */
@WorkerThread
public static @NonNull Recipient externalContact(@NonNull Context context, @NonNull String identifier) {
  RecipientDatabase db = DatabaseFactory.getRecipientDatabase(context);
  RecipientId       id = null;

  if (UuidUtil.isUuid(identifier)) {
    throw new UuidRecipientError();
  } else if (NumberUtil.isValidEmail(identifier)) {
    id = db.getOrInsertFromEmail(identifier);
  } else {
    id = db.getOrInsertFromE164(identifier);
  }

  return Recipient.resolved(id);
}
 
Example #4
Source File: GroupChangeUtil_resolveConflict_Test.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void field_4__changes_to_remove_missing_members_are_excluded() {
  UUID                 member1         = UUID.randomUUID();
  UUID                 member2         = UUID.randomUUID();
  UUID                 member3         = UUID.randomUUID();
  DecryptedGroup       groupState      = DecryptedGroup.newBuilder()
                                                       .addMembers(member(member2))
                                                       .build();
  DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder()
                                                             .addDeleteMembers(UuidUtil.toByteString(member1))
                                                             .addDeleteMembers(UuidUtil.toByteString(member2))
                                                             .addDeleteMembers(UuidUtil.toByteString(member3))
                                                             .build();
  GroupChange.Actions  change          = GroupChange.Actions.newBuilder()
                                                            .addDeleteMembers(GroupChange.Actions.DeleteMemberAction.newBuilder().setDeletedUserId(encrypt(member1)))
                                                            .addDeleteMembers(GroupChange.Actions.DeleteMemberAction.newBuilder().setDeletedUserId(encrypt(member2)))
                                                            .addDeleteMembers(GroupChange.Actions.DeleteMemberAction.newBuilder().setDeletedUserId(encrypt(member3)))
                                                            .build();

  GroupChange.Actions resolvedActions = GroupChangeUtil.resolveConflict(groupState, decryptedChange, change).build();

  GroupChange.Actions expected = GroupChange.Actions.newBuilder()
                                                    .addDeleteMembers(GroupChange.Actions.DeleteMemberAction.newBuilder().setDeletedUserId(encrypt(member2)))
                                                    .build();
  assertEquals(expected, resolvedActions);
}
 
Example #5
Source File: MessageGroupContext.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public @NonNull List<RecipientId> getMembersListExcludingSelf() {
  List<GroupContext.Member> membersList = groupContext.getMembersList();
  if (membersList.isEmpty()) {
    return Collections.emptyList();
  } else {
    LinkedList<RecipientId> members = new LinkedList<>();

    for (GroupContext.Member member : membersList) {
      RecipientId recipient = RecipientId.from(UuidUtil.parseOrNull(member.getUuid()), member.getE164());
      if (!Recipient.self().getId().equals(recipient)) {
        members.add(recipient);
      }
    }
    return members;
  }
}
 
Example #6
Source File: SignalServiceCipher.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private SignalServiceDataMessage.Quote createQuote(DataMessage content) {
  if (!content.hasQuote()) return null;

  List<SignalServiceDataMessage.Quote.QuotedAttachment> attachments = new LinkedList<>();

  for (DataMessage.Quote.QuotedAttachment attachment : content.getQuote().getAttachmentsList()) {
    attachments.add(new SignalServiceDataMessage.Quote.QuotedAttachment(attachment.getContentType(),
                                                                        attachment.getFileName(),
                                                                        attachment.hasThumbnail() ? createAttachmentPointer(attachment.getThumbnail()) : null));
  }

  if (SignalServiceAddress.isValidAddress(content.getQuote().getAuthorUuid(), content.getQuote().getAuthorE164())) {
    SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(content.getQuote().getAuthorUuid()), content.getQuote().getAuthorE164());

    return new SignalServiceDataMessage.Quote(content.getQuote().getId(),
                                              address,
                                              content.getQuote().getText(),
                                              attachments);
  } else {
    Log.w(TAG, "Quote was missing an author! Returning null.");
    return null;
  }
}
 
Example #7
Source File: DecryptedGroupUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Removes the uuid from the full members of a group.
 * <p>
 * Generally not expected to have to do this, just in the case of leaving a group where you cannot
 * get the new group state as you are not in the group any longer.
 */
public static DecryptedGroup removeMember(DecryptedGroup group, UUID uuid, int revision) {
  DecryptedGroup.Builder     builder          = DecryptedGroup.newBuilder(group);
  ByteString                 uuidString       = UuidUtil.toByteString(uuid);
  boolean                    removed          = false;
  ArrayList<DecryptedMember> decryptedMembers = new ArrayList<>(builder.getMembersList());
  Iterator<DecryptedMember>  membersList      = decryptedMembers.iterator();

  while (membersList.hasNext()) {
    if (uuidString.equals(membersList.next().getUuid())) {
      membersList.remove();
      removed = true;
    }
  }

  if (removed) {
    return builder.clearMembers()
                  .addAllMembers(decryptedMembers)
                  .setRevision(revision)
                  .build();
  } else {
    return group;
  }
}
 
Example #8
Source File: PushServiceSocket.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
public UUID verifyAccountCode(String verificationCode, String signalingKey, int registrationId, boolean fetchesMessages, String pin,
                              byte[] unidentifiedAccessKey, boolean unrestrictedUnidentifiedAccess)
    throws IOException
{
  AccountAttributes     signalingKeyEntity = new AccountAttributes(signalingKey, registrationId, fetchesMessages, pin, unidentifiedAccessKey, unrestrictedUnidentifiedAccess);
  String                requestBody        = JsonUtil.toJson(signalingKeyEntity);
  String                responseBody       = makeServiceRequest(String.format(VERIFY_ACCOUNT_CODE_PATH, verificationCode), "PUT", requestBody);
  VerifyAccountResponse response           = JsonUtil.fromJson(responseBody, VerifyAccountResponse.class);
  Optional<UUID>        uuid               = UuidUtil.parse(response.getUuid());

  if (uuid.isPresent()) {
    return uuid.get();
  } else {
    throw new IOException("Invalid UUID!");
  }
}
 
Example #9
Source File: Utils.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
static String computeSafetyNumber(SignalServiceAddress ownAddress, IdentityKey ownIdentityKey, SignalServiceAddress theirAddress, IdentityKey theirIdentityKey) {
    int version;
    byte[] ownId;
    byte[] theirId;

    if (ServiceConfig.capabilities.isUuid()
            && ownAddress.getUuid().isPresent() && theirAddress.getUuid().isPresent()) {
        // Version 2: UUID user
        version = 2;
        ownId = UuidUtil.toByteArray(ownAddress.getUuid().get());
        theirId = UuidUtil.toByteArray(theirAddress.getUuid().get());
    } else {
        // Version 1: E164 user
        version = 1;
        if (!ownAddress.getNumber().isPresent() || !theirAddress.getNumber().isPresent()) {
            return "INVALID ID";
        }
        ownId = ownAddress.getNumber().get().getBytes();
        theirId = theirAddress.getNumber().get().getBytes();
    }

    Fingerprint fingerprint = new NumericFingerprintGenerator(5200).createFor(version, ownId, ownIdentityKey, theirId, theirIdentityKey);
    return fingerprint.getDisplayableFingerprint().getDisplayText();
}
 
Example #10
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static SignalServiceDataMessage.Reaction createReaction(SignalServiceProtos.DataMessage content) {
  if (!content.hasReaction()                                                                        ||
      !content.getReaction().hasEmoji()                                                             ||
      !(content.getReaction().hasTargetAuthorE164() || content.getReaction().hasTargetAuthorUuid()) ||
      !content.getReaction().hasTargetSentTimestamp())
  {
    return null;
  }

  SignalServiceProtos.DataMessage.Reaction reaction = content.getReaction();

  return new SignalServiceDataMessage.Reaction(reaction.getEmoji(),
                      reaction.getRemove(),
                      new SignalServiceAddress(UuidUtil.parseOrNull(reaction.getTargetAuthorUuid()), reaction.getTargetAuthorE164()),
                      reaction.getTargetSentTimestamp());
}
 
Example #11
Source File: SignalServiceContent.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static SignalServiceDataMessage.Quote createQuote(SignalServiceProtos.DataMessage content) throws ProtocolInvalidMessageException {
  if (!content.hasQuote()) return null;

  List<SignalServiceDataMessage.Quote.QuotedAttachment> attachments = new LinkedList<>();

  for (SignalServiceProtos.DataMessage.Quote.QuotedAttachment attachment : content.getQuote().getAttachmentsList()) {
    attachments.add(new SignalServiceDataMessage.Quote.QuotedAttachment(attachment.getContentType(),
                                                                        attachment.getFileName(),
                                                                        attachment.hasThumbnail() ? createAttachmentPointer(attachment.getThumbnail()) : null));
  }

  if (SignalServiceAddress.isValidAddress(content.getQuote().getAuthorUuid(), content.getQuote().getAuthorE164())) {
    SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(content.getQuote().getAuthorUuid()), content.getQuote().getAuthorE164());

    return new SignalServiceDataMessage.Quote(content.getQuote().getId(),
                                              address,
                                              content.getQuote().getText(),
                                              attachments);
  } else {
    Log.w(TAG, "Quote was missing an author! Returning null.");
    return null;
  }
}
 
Example #12
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
public void verifyAccount(String verificationCode, String pin) throws IOException {
    verificationCode = verificationCode.replace("-", "");
    account.setSignalingKey(KeyUtils.createSignalingKey());
    // TODO make unrestricted unidentified access configurable
    VerifyAccountResponse response = accountManager.verifyAccountWithCode(verificationCode, account.getSignalingKey(), account.getSignalProtocolStore().getLocalRegistrationId(), true, pin, null, getSelfUnidentifiedAccessKey(), false, ServiceConfig.capabilities);

    UUID uuid = UuidUtil.parseOrNull(response.getUuid());
    // TODO response.isStorageCapable()
    //accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
    account.setRegistered(true);
    account.setUuid(uuid);
    account.setRegistrationLockPin(pin);
    account.getSignalProtocolStore().saveIdentity(account.getSelfAddress(), getIdentityKeyPair().getPublicKey(), TrustLevel.TRUSTED_VERIFIED);

    refreshPreKeys();
    account.save();
}
 
Example #13
Source File: MessageRecord.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public @NonNull String describe(@NonNull UUID uuid) {
  if (UuidUtil.UNKNOWN_UUID.equals(uuid)) {
    return context.getString(R.string.MessageRecord_unknown);
  }
  return Recipient.resolved(RecipientId.from(uuid, null)).toShortString(context);
}
 
Example #14
Source File: DecryptedGroupUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static Optional<DecryptedMember> findMemberByUuid(Collection<DecryptedMember> members, UUID uuid) {
  ByteString uuidBytes = UuidUtil.toByteString(uuid);

  for (DecryptedMember member : members) {
    if (uuidBytes.equals(member.getUuid())) {
      return Optional.of(member);
    }
  }

  return Optional.absent();
}
 
Example #15
Source File: SignalContactRecord.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public SignalContactRecord(StorageId id, ContactRecord proto) {
  this.id    = id;
  this.proto = proto;

  this.address     = new SignalServiceAddress(UuidUtil.parseOrNull(proto.getServiceUuid()), proto.getServiceE164());
  this.givenName   = OptionalUtil.absentIfEmpty(proto.getGivenName());
  this.familyName  = OptionalUtil.absentIfEmpty(proto.getFamilyName());
  this.profileKey  = OptionalUtil.absentIfEmpty(proto.getProfileKey());
  this.username    = OptionalUtil.absentIfEmpty(proto.getUsername());
  this.identityKey = OptionalUtil.absentIfEmpty(proto.getIdentityKey());
}
 
Example #16
Source File: ProtoTestUtils.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Emulates a presentation by concatenating the uuid and profile key which makes it suitable for
 * equality assertions in these tests.
 */
static ByteString presentation(UUID uuid, ProfileKey profileKey) {
  byte[] uuidBytes       = UuidUtil.toByteArray(uuid);
  byte[] profileKeyBytes = profileKey.serialize();
  byte[] concat          = new byte[uuidBytes.length + profileKeyBytes.length];

  System.arraycopy(uuidBytes, 0, concat, 0, uuidBytes.length);
  System.arraycopy(profileKeyBytes, 0, concat, uuidBytes.length, profileKeyBytes.length);

  return ByteString.copyFrom(concat);
}
 
Example #17
Source File: DecryptedGroupUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static Optional<DecryptedPendingMember> findPendingByUuid(Collection<DecryptedPendingMember> members, UUID uuid) {
  ByteString uuidBytes = UuidUtil.toByteString(uuid);

  for (DecryptedPendingMember member : members) {
    if (uuidBytes.equals(member.getUuid())) {
      return Optional.of(member);
    }
  }

  return Optional.absent();
}
 
Example #18
Source File: DecryptedGroupUtilTest.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void can_extract_editor_uuid_from_decrypted_group_change() {
  UUID                 uuid        = UUID.randomUUID();
  ByteString           editor      = UuidUtil.toByteString(uuid);
  DecryptedGroupChange groupChange = DecryptedGroupChange.newBuilder()
                                                         .setEditor(editor)
                                                         .build();

  UUID parsed = DecryptedGroupUtil.editorUuid(groupChange).get();

  assertEquals(uuid, parsed);
}
 
Example #19
Source File: GroupsV2StateProcessor.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void storeMessage(@NonNull DecryptedGroupV2Context decryptedGroupV2Context, long timestamp) {
  Optional<UUID> editor = getEditor(decryptedGroupV2Context);

  if (!editor.isPresent() || UuidUtil.UNKNOWN_UUID.equals(editor.get())) {
    Log.w(TAG, "Cannot determine editor of change, can't insert message");
    return;
  }

  boolean outgoing = Recipient.self().requireUuid().equals(editor.get());

  if (outgoing) {
    try {
      MmsDatabase                mmsDatabase     = DatabaseFactory.getMmsDatabase(context);
      RecipientId                recipientId     = recipientDatabase.getOrInsertFromGroupId(groupId);
      Recipient                  recipient       = Recipient.resolved(recipientId);
      OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(recipient, decryptedGroupV2Context, null, timestamp, 0, false, null, Collections.emptyList(), Collections.emptyList());
      long                       threadId        = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
      long                       messageId       = mmsDatabase.insertMessageOutbox(outgoingMessage, threadId, false, null);

      mmsDatabase.markAsSent(messageId, true);
    } catch (MmsException e) {
      Log.w(TAG, e);
    }
  } else {
    SmsDatabase                smsDatabase  = DatabaseFactory.getSmsDatabase(context);
    RecipientId                sender       = RecipientId.from(editor.get(), null);
    IncomingTextMessage        incoming     = new IncomingTextMessage(sender, -1, timestamp, timestamp, "", Optional.of(groupId), 0, false);
    IncomingGroupUpdateMessage groupMessage = new IncomingGroupUpdateMessage(incoming, decryptedGroupV2Context);

    smsDatabase.insertMessageInbox(groupMessage);
  }
}
 
Example #20
Source File: GroupsV2StateProcessor.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private Optional<UUID> getEditor(@NonNull DecryptedGroupV2Context decryptedGroupV2Context) {
  DecryptedGroupChange change       = decryptedGroupV2Context.getChange();
  Optional<UUID>       changeEditor = DecryptedGroupUtil.editorUuid(change);
  if (changeEditor.isPresent()) {
    return changeEditor;
  } else {
    Optional<DecryptedPendingMember> pendingByUuid = DecryptedGroupUtil.findPendingByUuid(decryptedGroupV2Context.getGroupState().getPendingMembersList(), Recipient.self().requireUuid());
    if (pendingByUuid.isPresent()) {
      return Optional.fromNullable(UuidUtil.fromByteStringOrNull(pendingByUuid.get().getAddedByUuid()));
    }
  }
  return Optional.absent();
}
 
Example #21
Source File: ProfileKeySet.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add new profile keys from the group state.
 */
public void addKeysFromGroupState(@NonNull DecryptedGroup group,
                                  @Nullable UUID changeSource)
{
  for (DecryptedMember member : group.getMembersList()) {
    UUID memberUuid = UuidUtil.fromByteString(member.getUuid());

    if (UuidUtil.UNKNOWN_UUID.equals(memberUuid)) {
      Log.w(TAG, "Seen unknown member UUID");
      continue;
    }

    ProfileKey profileKey;
    try {
      profileKey = new ProfileKey(member.getProfileKey().toByteArray());
    } catch (InvalidInputException e) {
      Log.w(TAG, "Bad profile key in group");
      continue;
    }

    if (changeSource != null) {
      Log.d(TAG, String.format("Change %s by %s", memberUuid, changeSource));

      if (changeSource.equals(memberUuid)) {
        authoritativeProfileKeys.put(memberUuid, profileKey);
        profileKeys.remove(memberUuid);
      } else {
        if (!authoritativeProfileKeys.containsKey(memberUuid)) {
          profileKeys.put(memberUuid, profileKey);
        }
      }
    }
  }
}
 
Example #22
Source File: GroupProtoUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isMember(@NonNull UUID uuid, @NonNull List<DecryptedMember> membersList) {
  ByteString uuidBytes = UuidUtil.toByteString(uuid);

  for (DecryptedMember member : membersList) {
    if (uuidBytes.equals(member.getUuid())) {
      return true;
    }
  }

  return false;
}
 
Example #23
Source File: GroupsV2UpdateMessageProducer.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param descriptionStrategy Strategy for member description.
 */
GroupsV2UpdateMessageProducer(@NonNull Context context,
                              @NonNull DescribeMemberStrategy descriptionStrategy,
                              @NonNull UUID selfUuid)
{
  this.context             = context;
  this.descriptionStrategy = descriptionStrategy;
  this.selfUuid            = selfUuid;
  this.selfUuidBytes       = UuidUtil.toByteString(selfUuid);
}
 
Example #24
Source File: JsonSessionStore.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
@Override
public JsonSessionStore deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    JsonNode node = jsonParser.getCodec().readTree(jsonParser);

    JsonSessionStore sessionStore = new JsonSessionStore();

    if (node.isArray()) {
        for (JsonNode session : node) {
            String sessionName = session.has("name")
                    ? session.get("name").asText()
                    : null;
            if (UuidUtil.isUuid(sessionName)) {
                // Ignore sessions that were incorrectly created with UUIDs as name
                continue;
            }

            UUID uuid = session.hasNonNull("uuid")
                    ? UuidUtil.parseOrNull(session.get("uuid").asText())
                    : null;
            final SignalServiceAddress serviceAddress = uuid == null
                    ? Util.getSignalServiceAddressFromIdentifier(sessionName)
                    : new SignalServiceAddress(uuid, sessionName);
            final int deviceId = session.get("deviceId").asInt();
            final String record = session.get("record").asText();
            try {
                SessionInfo sessionInfo = new SessionInfo(serviceAddress, deviceId, Base64.decode(record));
                sessionStore.sessions.add(sessionInfo);
            } catch (IOException e) {
                System.out.println(String.format("Error while decoding session for: %s", sessionName));
            }
        }
    }

    return sessionStore;
}
 
Example #25
Source File: Recipient.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a fully-populated {@link Recipient} based off of a string identifier, creating one in
 * the database if necessary. The identifier may be a uuid, phone number, email,
 * or serialized groupId.
 *
 * If the identifier is a UUID of a Signal user, prefer using
 * {@link #externalPush(Context, UUID, String)} or its overload, as this will let us associate
 * the phone number with the recipient.
 */
@WorkerThread
public static @NonNull Recipient external(@NonNull Context context, @NonNull String identifier) {
  Preconditions.checkNotNull(identifier, "Identifier cannot be null!");

  RecipientDatabase db = DatabaseFactory.getRecipientDatabase(context);
  RecipientId       id = null;

  if (UuidUtil.isUuid(identifier)) {
    UUID uuid = UuidUtil.parseOrThrow(identifier);

    if (FeatureFlags.uuids()) {
      id = db.getOrInsertFromUuid(uuid);
    } else {
      Optional<RecipientId> possibleId = db.getByUuid(uuid);

      if (possibleId.isPresent()) {
        id = possibleId.get();
      } else {
        if (!FeatureFlags.uuids() && FeatureFlags.groupsV2()) {
          throw new RuntimeException(new UuidRecipientError());
        } else {
          throw new UuidRecipientError();
        }
      }
    }
  } else if (GroupId.isEncodedGroup(identifier)) {
    id = db.getOrInsertFromGroupId(GroupId.parseOrThrow(identifier));
  } else if (NumberUtil.isValidEmail(identifier)) {
    id = db.getOrInsertFromEmail(identifier);
  } else {
    String e164 = PhoneNumberFormatter.get(context).format(identifier);
    id = db.getOrInsertFromE164(e164);
  }

  return Recipient.resolved(id);
}
 
Example #26
Source File: MessageGroupContext.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public @NonNull List<UUID> getAllActivePendingAndRemovedMembers() {
  LinkedList<UUID> memberUuids = new LinkedList<>();

  memberUuids.addAll(DecryptedGroupUtil.membersToUuidList(decryptedGroupV2Context.getGroupState().getMembersList()));
  memberUuids.addAll(DecryptedGroupUtil.pendingToUuidList(decryptedGroupV2Context.getGroupState().getPendingMembersList()));
  memberUuids.addAll(DecryptedGroupUtil.removedMembersUuidList(decryptedGroupV2Context.getChange()));

  return UuidUtil.filterKnown(memberUuids);
}
 
Example #27
Source File: MessageGroupContext.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public @NonNull List<RecipientId> getMembersListExcludingSelf() {
  List<RecipientId> members = new ArrayList<>(decryptedGroupV2Context.getGroupState().getMembersCount());

  for (DecryptedMember member : decryptedGroupV2Context.getGroupState().getMembersList()) {
    RecipientId recipient = RecipientId.from(UuidUtil.fromByteString(member.getUuid()), null);
    if (!Recipient.self().getId().equals(recipient)) {
      members.add(recipient);
    }
  }

  return members;
}
 
Example #28
Source File: SignalServiceAddress.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public static Optional<SignalServiceAddress> fromRaw(String rawUuid, String e164) {
  if (isValidAddress(rawUuid, e164)) {
    return Optional.of(new SignalServiceAddress(UuidUtil.parseOrNull(rawUuid), e164));
  } else {
    return Optional.absent();
  }
}
 
Example #29
Source File: Util.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceAddress getSignalServiceAddressFromIdentifier(final String identifier) {
    if (UuidUtil.isUuid(identifier)) {
        return new SignalServiceAddress(UuidUtil.parseOrNull(identifier), null);
    } else {
        return new SignalServiceAddress(null, identifier);
    }
}
 
Example #30
Source File: PushServiceSocket.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public UUID getOwnUuid() throws IOException {
  String         body     = makeServiceRequest(WHO_AM_I, "GET", null);
  WhoAmIResponse response = JsonUtil.fromJson(body, WhoAmIResponse.class);
  Optional<UUID> uuid     = UuidUtil.parse(response.getUuid());

  if (uuid.isPresent()) {
    return uuid.get();
  } else {
    throw new IOException("Invalid UUID!");
  }
}