Search in sources :

Example 1 with ContactsDatabase

use of org.thoughtcrime.securesms.contacts.ContactsDatabase in project Signal-Android by WhisperSystems.

the class DirectoryHelper method updateContactsDatabase.

private static void updateContactsDatabase(@NonNull Context context, @NonNull Collection<RecipientId> activeIds, boolean removeMissing, @NonNull Map<String, String> rewrites) {
    if (!Permissions.hasAll(context, Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)) {
        Log.w(TAG, "[updateContactsDatabase] No contact permissions. Skipping.");
        return;
    }
    AccountHolder account = getOrCreateSystemAccount(context);
    if (account == null) {
        Log.w(TAG, "Failed to create an account!");
        return;
    }
    try {
        ContactsDatabase contactsDatabase = SignalDatabase.contacts();
        List<String> activeAddresses = Stream.of(activeIds).map(Recipient::resolved).filter(Recipient::hasE164).map(Recipient::requireE164).toList();
        contactsDatabase.removeDeletedRawContacts(account.getAccount());
        contactsDatabase.setRegisteredUsers(account.getAccount(), activeAddresses, removeMissing);
        syncRecipientInfoWithSystemContacts(context, rewrites);
    } catch (RemoteException | OperationApplicationException e) {
        Log.w(TAG, "Failed to update contacts.", e);
    }
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) ContactsDatabase(org.thoughtcrime.securesms.contacts.ContactsDatabase) RemoteException(android.os.RemoteException) OperationApplicationException(android.content.OperationApplicationException)

Aggregations

OperationApplicationException (android.content.OperationApplicationException)1 RemoteException (android.os.RemoteException)1 ContactsDatabase (org.thoughtcrime.securesms.contacts.ContactsDatabase)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1