Java Code Examples for org.whispersystems.signalservice.api.push.ContactTokenDetails#setNumber()

The following examples show how to use org.whispersystems.signalservice.api.push.ContactTokenDetails#setNumber() . 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: SignalServiceAccountManager.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks whether a contact is currently registered with the server.
 *
 * @param e164number The contact to check.
 * @return An optional ContactTokenDetails, present if registered, absent if not.
 * @throws IOException
 */
public Optional<ContactTokenDetails> getContact(String e164number) throws IOException {
  String              contactToken        = createDirectoryServerToken(e164number, true);
  ContactTokenDetails contactTokenDetails = this.pushServiceSocket.getContactTokenDetails(contactToken);

  if (contactTokenDetails != null) {
    contactTokenDetails.setNumber(e164number);
  }

  return Optional.fromNullable(contactTokenDetails);
}
 
Example 2
Source File: SignalServiceAccountManager.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks which contacts in a set are registered with the server.
 *
 * @param e164numbers The contacts to check.
 * @return A list of ContactTokenDetails for the registered users.
 * @throws IOException
 */
public List<ContactTokenDetails> getContacts(Set<String> e164numbers)
    throws IOException
{
  Map<String, String>       contactTokensMap = createDirectoryServerTokenMap(e164numbers);
  List<ContactTokenDetails> activeTokens     = this.pushServiceSocket.retrieveDirectory(contactTokensMap.keySet());

  for (ContactTokenDetails activeToken : activeTokens) {
    activeToken.setNumber(contactTokensMap.get(activeToken.getToken()));
  }

  return activeTokens;
}
 
Example 3
Source File: SignalServiceAccountManager.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks whether a contact is currently registered with the server.
 *
 * @param e164number The contact to check.
 * @return An optional ContactTokenDetails, present if registered, absent if not.
 * @throws IOException
 */
public Optional<ContactTokenDetails> getContact(String e164number) throws IOException {
  String              contactToken        = createDirectoryServerToken(e164number, true);
  ContactTokenDetails contactTokenDetails = this.pushServiceSocket.getContactTokenDetails(contactToken);

  if (contactTokenDetails != null) {
    contactTokenDetails.setNumber(e164number);
  }

  return Optional.fromNullable(contactTokenDetails);
}
 
Example 4
Source File: SignalServiceAccountManager.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks which contacts in a set are registered with the server.
 *
 * @param e164numbers The contacts to check.
 * @return A list of ContactTokenDetails for the registered users.
 * @throws IOException
 */
public List<ContactTokenDetails> getContacts(Set<String> e164numbers)
    throws IOException
{
  Map<String, String>       contactTokensMap = createDirectoryServerTokenMap(e164numbers);
  List<ContactTokenDetails> activeTokens     = this.pushServiceSocket.retrieveDirectory(contactTokensMap.keySet());

  for (ContactTokenDetails activeToken : activeTokens) {
    activeToken.setNumber(contactTokensMap.get(activeToken.getToken()));
  }

  return activeTokens;
}
 
Example 5
Source File: DirectoryHelperV1.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static RegisteredState getRegisteredState(@NonNull Context                     context,
                                                  @NonNull SignalServiceAccountManager accountManager,
                                                  @NonNull RecipientDatabase           recipientDatabase,
                                                  @NonNull Recipient                   recipient)
    throws IOException
{
  boolean                       activeUser    = recipient.resolve().getRegistered() == RegisteredState.REGISTERED;
  boolean                       systemContact = recipient.isSystemContact();
  Optional<ContactTokenDetails> details       = Optional.absent();
  Map<String, String>           rewrites      = new HashMap<>();

  if (recipient.hasE164()) {
    FuzzyPhoneNumberHelper.InputResult inputResult = FuzzyPhoneNumberHelper.generateInput(Collections.singletonList(recipient.requireE164()), recipientDatabase.getAllPhoneNumbers());

    if (inputResult.getNumbers().size() > 1) {
      Log.i(TAG, "[getRegisteredState] Got a fuzzy number result.");

      List<ContactTokenDetails>           detailList   = accountManager.getContacts(inputResult.getNumbers());
      Collection<String>                  registered   = Stream.of(detailList).map(ContactTokenDetails::getNumber).collect(Collectors.toSet());
      FuzzyPhoneNumberHelper.OutputResult outputResult = FuzzyPhoneNumberHelper.generateOutput(registered, inputResult);
      String                              finalNumber  = recipient.requireE164();
      ContactTokenDetails                 detail       = new ContactTokenDetails();

      if (outputResult.getRewrites().size() > 0 && outputResult.getRewrites().containsKey(finalNumber)) {
        Log.i(TAG, "[getRegisteredState] Need to rewrite a number.");
        finalNumber = outputResult.getRewrites().get(finalNumber);
        rewrites    = outputResult.getRewrites();
      }

      detail.setNumber(finalNumber);
      details = Optional.of(detail);

      recipientDatabase.updatePhoneNumbers(outputResult.getRewrites());
    } else {
      details = accountManager.getContact(recipient.requireE164());
    }
  }

  if (details.isPresent()) {
    recipientDatabase.setRegistered(recipient.getId(), RegisteredState.REGISTERED);

    if (Permissions.hasAll(context, Manifest.permission.WRITE_CONTACTS)) {
      updateContactsDatabase(context, Util.asList(recipient.getId()), false, rewrites);
    }

    if (!activeUser && TextSecurePreferences.isMultiDevice(context)) {
      ApplicationDependencies.getJobManager().add(new MultiDeviceContactUpdateJob());
    }

    if (!activeUser && systemContact) {
      notifyNewUsers(context, Collections.singletonList(recipient.getId()));
    }

    return RegisteredState.REGISTERED;
  } else {
    recipientDatabase.setRegistered(recipient.getId(), RegisteredState.NOT_REGISTERED);
    return RegisteredState.NOT_REGISTERED;
  }
}