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

The following examples show how to use org.whispersystems.signalservice.api.util.InvalidNumberException. 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: MultiDeviceContactUpdateJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private Optional<VerifiedMessage> getVerifiedMessage(Recipient recipient, Optional<IdentityDatabase.IdentityRecord> identity) throws InvalidNumberException {
  if (!identity.isPresent()) return Optional.absent();

  SignalServiceAddress destination = RecipientUtil.toSignalServiceAddress(context, recipient);
  IdentityKey          identityKey = identity.get().getIdentityKey();

  VerifiedMessage.VerifiedState state;

  switch (identity.get().getVerifiedStatus()) {
    case VERIFIED:   state = VerifiedMessage.VerifiedState.VERIFIED;   break;
    case UNVERIFIED: state = VerifiedMessage.VerifiedState.UNVERIFIED; break;
    case DEFAULT:    state = VerifiedMessage.VerifiedState.DEFAULT;    break;
    default: throw new AssertionError("Unknown state: " + identity.get().getVerifiedStatus());
  }

  return Optional.of(new VerifiedMessage(destination, identityKey, state, System.currentTimeMillis()));
}
 
Example #2
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
public long sendMessage(String messageText, List<String> attachments,
                        List<String> recipients)
        throws IOException, EncapsulatedExceptions, AttachmentInvalidException, InvalidNumberException {
    final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
    if (attachments != null) {
        List<SignalServiceAttachment> attachmentStreams = Utils.getSignalServiceAttachments(attachments);

        // Upload attachments here, so we only upload once even for multiple recipients
        SignalServiceMessageSender messageSender = getMessageSender();
        List<SignalServiceAttachment> attachmentPointers = new ArrayList<>(attachmentStreams.size());
        for (SignalServiceAttachment attachment : attachmentStreams) {
            if (attachment.isStream()) {
                attachmentPointers.add(messageSender.uploadAttachment(attachment.asStream()));
            } else if (attachment.isPointer()) {
                attachmentPointers.add(attachment.asPointer());
            }
        }

        messageBuilder.withAttachments(attachmentPointers);
    }
    return sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients));
}
 
Example #3
Source File: ListIdentitiesCommand.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int handleCommand(final Namespace ns, final Manager m) {
    if (!m.isRegistered()) {
        System.err.println("User is not registered.");
        return 1;
    }
    if (ns.get("number") == null) {
        for (JsonIdentityKeyStore.Identity identity : m.getIdentities()) {
            printIdentityFingerprint(m, identity);
        }
    } else {
        String number = ns.getString("number");
        try {
            List<JsonIdentityKeyStore.Identity> identities = m.getIdentities(number);
            for (JsonIdentityKeyStore.Identity id : identities) {
                printIdentityFingerprint(m, id);
            }
        } catch (InvalidNumberException e) {
            System.out.println("Invalid number: " + e.getMessage());
        }
    }
    return 0;
}
 
Example #4
Source File: PhoneNumberFormatterTest.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
public void testFormatNumberE164() throws Exception, InvalidNumberException {
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_UK, "(020) 7946 0018")).isEqualTo(NUMBER_UK);
//    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_UK, "044 20 7946 0018")).isEqualTo(NUMBER_UK);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_UK, "+442079460018")).isEqualTo(NUMBER_UK);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_UK, "+4402079460018")).isEqualTo(NUMBER_UK);

    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_CH, "+41 44 668 18 00")).isEqualTo(NUMBER_CH);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_CH, "+41 (044) 6681800")).isEqualTo(NUMBER_CH);

    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0049 030 123456")).isEqualTo(NUMBER_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0049 (0)30123456")).isEqualTo(NUMBER_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0049((0)30)123456")).isEqualTo(NUMBER_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "+49 (0) 30  1 2  3 45 6 ")).isEqualTo(NUMBER_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "030 123456")).isEqualTo(NUMBER_DE);

    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0171123456")).isEqualTo(NUMBER_MOBILE_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0171/123456")).isEqualTo(NUMBER_MOBILE_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "+490171/123456")).isEqualTo(NUMBER_MOBILE_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "00490171/123456")).isEqualTo(NUMBER_MOBILE_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0049171/123456")).isEqualTo(NUMBER_MOBILE_DE);
  }
 
Example #5
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Trust this the identity with this fingerprint
 *
 * @param name        username of the identity
 * @param fingerprint Fingerprint
 */
public boolean trustIdentityVerified(String name, byte[] fingerprint) throws InvalidNumberException {
    SignalServiceAddress address = canonicalizeAndResolveSignalServiceAddress(name);
    List<JsonIdentityKeyStore.Identity> ids = account.getSignalProtocolStore().getIdentities(address);
    if (ids == null) {
        return false;
    }
    for (JsonIdentityKeyStore.Identity id : ids) {
        if (!Arrays.equals(id.getIdentityKey().serialize(), fingerprint)) {
            continue;
        }

        account.getSignalProtocolStore().setIdentityTrustLevel(address, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
        try {
            sendVerifiedMessage(address, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
        } catch (IOException | UntrustedIdentityException e) {
            e.printStackTrace();
        }
        account.save();
        return true;
    }
    return false;
}
 
Example #6
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Trust this the identity with this safety number
 *
 * @param name         username of the identity
 * @param safetyNumber Safety number
 */
public boolean trustIdentityVerifiedSafetyNumber(String name, String safetyNumber) throws InvalidNumberException {
    SignalServiceAddress address = canonicalizeAndResolveSignalServiceAddress(name);
    List<JsonIdentityKeyStore.Identity> ids = account.getSignalProtocolStore().getIdentities(address);
    if (ids == null) {
        return false;
    }
    for (JsonIdentityKeyStore.Identity id : ids) {
        if (!safetyNumber.equals(computeSafetyNumber(address, id.getIdentityKey()))) {
            continue;
        }

        account.getSignalProtocolStore().setIdentityTrustLevel(address, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
        try {
            sendVerifiedMessage(address, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED);
        } catch (IOException | UntrustedIdentityException e) {
            e.printStackTrace();
        }
        account.save();
        return true;
    }
    return false;
}
 
Example #7
Source File: PhoneNumberFormatterTest.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Test
  public void testFormatNumberE164() throws Exception, InvalidNumberException {
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_UK, "(020) 7946 0018")).isEqualTo(NUMBER_UK);
//    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_UK, "044 20 7946 0018")).isEqualTo(NUMBER_UK);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_UK, "+442079460018")).isEqualTo(NUMBER_UK);

    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_CH, "+41 44 668 18 00")).isEqualTo(NUMBER_CH);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_CH, "+41 (044) 6681800")).isEqualTo(NUMBER_CH);

    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0049 030 123456")).isEqualTo(NUMBER_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0049 (0)30123456")).isEqualTo(NUMBER_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0049((0)30)123456")).isEqualTo(NUMBER_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "+49 (0) 30  1 2  3 45 6 ")).isEqualTo(NUMBER_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "030 123456")).isEqualTo(NUMBER_DE);

    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0171123456")).isEqualTo(NUMBER_MOBILE_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0171/123456")).isEqualTo(NUMBER_MOBILE_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "+490171/123456")).isEqualTo(NUMBER_MOBILE_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "00490171/123456")).isEqualTo(NUMBER_MOBILE_DE);
    assertThat(PhoneNumberFormatter.formatE164(COUNTRY_CODE_DE, "0049171/123456")).isEqualTo(NUMBER_MOBILE_DE);
  }
 
Example #8
Source File: DbusSignalImpl.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getContactName(final String number) {
    try {
        return m.getContactName(number);
    } catch (InvalidNumberException e) {
        throw new Error.InvalidNumber(e.getMessage());
    }
}
 
Example #9
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private Collection<SignalServiceAddress> getSignalServiceAddresses(Collection<String> numbers) throws InvalidNumberException {
    final Set<SignalServiceAddress> signalServiceAddresses = new HashSet<>(numbers.size());

    for (String number : numbers) {
        signalServiceAddresses.add(canonicalizeAndResolveSignalServiceAddress(number));
    }
    return signalServiceAddresses;
}
 
Example #10
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
    if (groupId.length == 0) {
        groupId = null;
    }
    if (name.isEmpty()) {
        name = null;
    }
    if (members.size() == 0) {
        members = null;
    }
    if (avatar.isEmpty()) {
        avatar = null;
    }
    return sendUpdateGroupMessage(groupId, name, members == null ? null : getSignalServiceAddresses(members), avatar);
}
 
Example #11
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public void setContactName(String number, String name) throws InvalidNumberException {
    final SignalServiceAddress address = canonicalizeAndResolveSignalServiceAddress(number);
    ContactInfo contact = account.getContactStore().getContact(address);
    if (contact == null) {
        contact = new ContactInfo(address);
        System.err.println("Add contact " + contact.number + " named " + name);
    } else {
        System.err.println("Updating contact " + contact.number + " name " + contact.name + " -> " + name);
    }
    contact.name = name;
    account.getContactStore().updateContact(contact);
    account.save();
}
 
Example #12
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public String getContactName(String number) throws InvalidNumberException {
    ContactInfo contact = account.getContactStore().getContact(canonicalizeAndResolveSignalServiceAddress(number));
    if (contact == null) {
        return "";
    } else {
        return contact.name;
    }
}
 
Example #13
Source File: DbusSignalImpl.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setContactName(final String number, final String name) {
    try {
        m.setContactName(number, name);
    } catch (InvalidNumberException e) {
        throw new Error.InvalidNumber(e.getMessage());
    }
}
 
Example #14
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions, InvalidNumberException {
    SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
            .asEndSessionMessage();

    final Collection<SignalServiceAddress> signalServiceAddresses = getSignalServiceAddresses(recipients);
    try {
        sendMessageLegacy(messageBuilder, signalServiceAddresses);
    } catch (Exception e) {
        for (SignalServiceAddress address : signalServiceAddresses) {
            handleEndSession(address);
        }
        account.save();
        throw e;
    }
}
 
Example #15
Source File: DbusSignalImpl.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setContactBlocked(final String number, final boolean blocked) {
    try {
        m.setContactBlocked(number, blocked);
    } catch (InvalidNumberException e) {
        throw new Error.InvalidNumber(e.getMessage());
    }
}
 
Example #16
Source File: MultiDeviceContactUpdateJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void generateSingleContactUpdate(@NonNull RecipientId recipientId)
    throws IOException, UntrustedIdentityException, NetworkException
{
  File contactDataFile = createTempFile("multidevice-contact-update");

  try {
    DeviceContactsOutputStream                out             = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile));
    Recipient                                 recipient       = Recipient.resolved(recipientId);
    Optional<IdentityDatabase.IdentityRecord> identityRecord  = DatabaseFactory.getIdentityDatabase(context).getIdentity(recipient.getId());
    Optional<VerifiedMessage>                 verifiedMessage = getVerifiedMessage(recipient, identityRecord);
    Map<RecipientId, Integer>                 inboxPositions  = DatabaseFactory.getThreadDatabase(context).getInboxPositions();
    Set<RecipientId>                          archived        = DatabaseFactory.getThreadDatabase(context).getArchivedRecipients();

    out.write(new DeviceContact(RecipientUtil.toSignalServiceAddress(context, recipient),
                                Optional.of(recipient.getDisplayName(context)),
                                getAvatar(recipient.getId(), recipient.getContactUri()),
                                Optional.fromNullable(recipient.getColor().serialize()),
                                verifiedMessage,
                                ProfileKeyUtil.profileKeyOptional(recipient.getProfileKey()),
                                recipient.isBlocked(),
                                recipient.getExpireMessages() > 0 ? Optional.of(recipient.getExpireMessages())
                                                                  : Optional.absent(),
                                Optional.fromNullable(inboxPositions.get(recipientId)),
                                archived.contains(recipientId)));

    out.close();
    sendUpdate(ApplicationDependencies.getSignalServiceMessageSender(), contactDataFile, false);

  } catch(InvalidNumberException e) {
    Log.w(TAG, e);
  } finally {
    if (contactDataFile != null) contactDataFile.delete();
  }
}
 
Example #17
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public void sendMessageReaction(String emoji, boolean remove, String targetAuthor,
                                long targetSentTimestamp, List<String> recipients)
        throws IOException, EncapsulatedExceptions, InvalidNumberException {
    SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, canonicalizeAndResolveSignalServiceAddress(targetAuthor), targetSentTimestamp);
    final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
            .withReaction(reaction);
    sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients));
}
 
Example #18
Source File: PhoneNumberFormatterTest.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public void testFormatRemoteNumberE164() throws Exception, InvalidNumberException {
  assertThat(PhoneNumberFormatter.formatNumber(LOCAL_NUMBER_US, NUMBER_UK)).isEqualTo(LOCAL_NUMBER_US);
  assertThat(PhoneNumberFormatter.formatNumber(LOCAL_NUMBER_US, LOCAL_NUMBER_US)).isEqualTo(LOCAL_NUMBER_US);

  assertThat(PhoneNumberFormatter.formatNumber(NUMBER_UK, NUMBER_UK)).isEqualTo(NUMBER_UK);
  assertThat(PhoneNumberFormatter.formatNumber(NUMBER_CH, NUMBER_CH)).isEqualTo(NUMBER_CH);
  assertThat(PhoneNumberFormatter.formatNumber(NUMBER_DE, NUMBER_DE)).isEqualTo(NUMBER_DE);
  assertThat(PhoneNumberFormatter.formatNumber(NUMBER_MOBILE_DE, NUMBER_DE)).isEqualTo(NUMBER_MOBILE_DE);

  assertThat(PhoneNumberFormatter.formatNumber("+4402079460018", LOCAL_NUMBER_US)).isEqualTo(NUMBER_UK);
}
 
Example #19
Source File: PhoneNumberFormatterTest.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public void testFormatNumberEmail() throws Exception {
  try {
    PhoneNumberFormatter.formatNumber("[email protected]", LOCAL_NUMBER_US);
    throw new AssertionFailedError("should have thrown on email");
  } catch (InvalidNumberException ine) {
    // success
  }
}
 
Example #20
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
public void sendGroupMessageReaction(String emoji, boolean remove, String targetAuthor,
                                     long targetSentTimestamp, byte[] groupId)
        throws IOException, EncapsulatedExceptions, InvalidNumberException, NotAGroupMemberException, GroupNotFoundException {
    SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, canonicalizeAndResolveSignalServiceAddress(targetAuthor), targetSentTimestamp);
    final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
            .withReaction(reaction);
    if (groupId != null) {
        SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER)
                .withId(groupId)
                .build();
        messageBuilder.asGroupMessage(group);
    }
    final GroupInfo g = getGroupForSending(groupId);
    sendMessageLegacy(messageBuilder, g.getMembersWithout(account.getSelfAddress()));
}
 
Example #21
Source File: PhoneNumberFormatterTest.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testFormatNumberEmail() throws Exception {
  try {
    PhoneNumberFormatter.formatNumber("[email protected]", LOCAL_NUMBER_US);
    throw new AssertionFailedError("should have thrown on email");
  } catch (InvalidNumberException ine) {
    // success
  }
}
 
Example #22
Source File: Manager.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
private SignalServiceAddress getSignalServiceAddress(String recipient) throws IOException {
    try {
        return getPushAddress(recipient);
    } catch (InvalidNumberException e) {
        logger.warn("Failed to add recipient \"" + Util.redact(recipient) + "\": " + e.getMessage());
        logger.warn("Aborting sending.");
        accountData.save();
        return null;
    }
}
 
Example #23
Source File: ErrorUtils.java    From signal-cli with GNU General Public License v3.0 4 votes vote down vote up
public static void handleInvalidNumberException(InvalidNumberException e) {
    System.err.println("Failed to parse recipient: " + e.getMessage());
    System.err.println("Aborting sending.");
}
 
Example #24
Source File: Util.java    From signal-cli with GNU General Public License v3.0 4 votes vote down vote up
public static String canonicalizeNumber(String number, String localNumber) throws InvalidNumberException {
    return PhoneNumberFormatter.formatNumber(number, localNumber);
}
 
Example #25
Source File: PhoneNumberFormatterTest.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testFormatNumber() throws Exception, InvalidNumberException {
  assertThat(PhoneNumberFormatter.formatNumber("(555) 555-5555", LOCAL_NUMBER_US)).isEqualTo(LOCAL_NUMBER_US);
  assertThat(PhoneNumberFormatter.formatNumber("555-5555", LOCAL_NUMBER_US)).isEqualTo(LOCAL_NUMBER_US);
  assertThat(PhoneNumberFormatter.formatNumber("(123) 555-5555", LOCAL_NUMBER_US)).isNotEqualTo(LOCAL_NUMBER_US);
}
 
Example #26
Source File: PhoneNumberFormatterTest.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testFormatRemoteNumberE164() throws Exception, InvalidNumberException {
  assertThat(PhoneNumberFormatter.formatNumber("+4402079460018", LOCAL_NUMBER_US)).isEqualTo(NUMBER_UK);
}
 
Example #27
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 4 votes vote down vote up
public SignalServiceAddress canonicalizeAndResolveSignalServiceAddress(String identifier) throws InvalidNumberException {
    String canonicalizedNumber = UuidUtil.isUuid(identifier) ? identifier : Util.canonicalizeNumber(identifier, account.getUsername());
    return resolveSignalServiceAddress(canonicalizedNumber);
}
 
Example #28
Source File: Manager.java    From signald with GNU General Public License v3.0 4 votes vote down vote up
public byte[] sendUpdateGroupMessage(byte[] groupId, String name, Collection<String> members, String avatarFile) throws IOException, EncapsulatedExceptions, UntrustedIdentityException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
        GroupInfo g;
        if (groupId == null) {
            // Create new group
            g = new GroupInfo(Util.getSecretBytes(16));
            g.members.add(accountData.username);
        } else {
            g = getGroupForSending(groupId);
        }

        if (name != null) {
            g.name = name;
        }

        if (members != null) {
            Set<String> newMembers = new HashSet<>();
            for (String member : members) {
                try {
                    member = canonicalizeNumber(member);
                } catch (InvalidNumberException e) {
                    logger.warn("Failed to add member \"" + Util.redact(member) + "\" to group: " + e.getMessage());
                }
                if (g.members.contains(member)) {
                    continue;
                }
                newMembers.add(member);
                g.members.add(member);
            }
            final List<ContactTokenDetails> contacts = accountManager.getContacts(newMembers);
            if (contacts.size() != newMembers.size()) {
                // Some of the new members are not registered on Signal
                for (ContactTokenDetails contact : contacts) {
                    newMembers.remove(contact.getNumber());
                }
//                logger.warn("Failed to add members " + join(", ", newMembers) + " to group: Not registered on Signal");
            }
        }

        if (avatarFile != null) {
            createPrivateDirectories(avatarsPath);
            File aFile = getGroupAvatarFile(g.groupId);
            Files.copy(Paths.get(avatarFile), aFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        }

        accountData.groupStore.updateGroup(g);

        SignalServiceDataMessage.Builder messageBuilder = getGroupUpdateMessageBuilder(g);

        // Don't send group message to ourself
        final List<String> membersSend = new ArrayList<>(g.members);
        membersSend.remove(accountData.username);
        sendMessage(messageBuilder, membersSend);
        return g.groupId;
    }
 
Example #29
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 4 votes vote down vote up
public List<JsonIdentityKeyStore.Identity> getIdentities(String number) throws InvalidNumberException {
    return account.getSignalProtocolStore().getIdentities(canonicalizeAndResolveSignalServiceAddress(number));
}
 
Example #30
Source File: Manager.java    From signald with GNU General Public License v3.0 4 votes vote down vote up
private String canonicalizeNumber(String number) throws InvalidNumberException {
    String localNumber = accountData.username;
    return PhoneNumberFormatter.formatNumber(number, localNumber);
}