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);
}
}
Aggregations