Update contact DB on incoming messages

When we receive a Signal message from a previously unregistered
user, reflect that in the contact DB.

Fixes #3949
Closes #4492
// FREEBIE
This commit is contained in:
Moxie Marlinspike
2015-11-09 14:51:53 -08:00
parent fb8d6cb538
commit b136fed6f7
5 changed files with 100 additions and 36 deletions

View File

@@ -77,7 +77,8 @@ public class ContactsDatabase {
public synchronized @NonNull List<String> setRegisteredUsers(@NonNull Account account,
@NonNull String localNumber,
@NonNull List<ContactTokenDetails> registeredContacts)
@NonNull List<ContactTokenDetails> registeredContacts,
boolean remove)
throws RemoteException, OperationApplicationException
{
@@ -107,8 +108,10 @@ public class ContactsDatabase {
ContactTokenDetails tokenDetails = registeredNumbers.get(currentContactEntry.getKey());
if (tokenDetails == null) {
Log.w(TAG, "Removing number: " + currentContactEntry.getKey());
removeTextSecureRawContact(operations, account, currentContactEntry.getValue().getId());
if (remove) {
Log.w(TAG, "Removing number: " + currentContactEntry.getKey());
removeTextSecureRawContact(operations, account, currentContactEntry.getValue().getId());
}
} else if (tokenDetails.isVoice() && !currentContactEntry.getValue().isVoiceSupported()) {
Log.w(TAG, "Adding voice support: " + currentContactEntry.getKey());
addContactVoiceSupport(operations, currentContactEntry.getKey(), currentContactEntry.getValue().getId());
@@ -298,7 +301,9 @@ public class ContactsDatabase {
.build());
}
private @NonNull Map<String, SignalContact> getSignalRawContacts(Account account, String localNumber) {
private @NonNull Map<String, SignalContact> getSignalRawContacts(@NonNull Account account,
@NonNull String localNumber)
{
Uri currentContactsUri = RawContacts.CONTENT_URI.buildUpon()
.appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
.appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();