Only notify when address is in contacts

This commit is contained in:
Moxie Marlinspike 2017-12-07 11:53:17 -08:00
parent 27d3dc918e
commit b58c87a56b
2 changed files with 18 additions and 2 deletions

View File

@ -354,6 +354,19 @@ public class RecipientDatabase extends Database {
return results;
}
public List<Address> getSystemContacts() {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
List<Address> results = new LinkedList<>();
try (Cursor cursor = db.query(TABLE_NAME, new String[] {ADDRESS}, SYSTEM_DISPLAY_NAME + " IS NOT NULL AND " + SYSTEM_DISPLAY_NAME + " != \"\"", null, null, null, null)) {
while (cursor != null && cursor.moveToNext()) {
results.add(Address.fromSerialized(cursor.getString(0)));
}
}
return results;
}
// XXX This shouldn't be here, and is just a temporary workaround
public RegisteredState isRegistered(@NonNull Address address) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();

View File

@ -67,7 +67,7 @@ public class DirectoryHelper {
if (notifyOfNewUsers) notifyNewUsers(context, masterSecret, newlyActiveUsers);
}
public static @NonNull List<Address> refreshDirectory(@NonNull Context context, @NonNull SignalServiceAccountManager accountManager)
private static @NonNull List<Address> refreshDirectory(@NonNull Context context, @NonNull SignalServiceAccountManager accountManager)
throws IOException
{
if (TextUtils.isEmpty(TextSecurePreferences.getLocalNumber(context))) {
@ -101,8 +101,10 @@ public class DirectoryHelper {
}
Set<Address> currentActiveAddresses = new HashSet<>(recipientDatabase.getRegistered());
Set<Address> contactAddresses = new HashSet<>(recipientDatabase.getSystemContacts());
List<Address> newlyActiveAddresses = Stream.of(activeAddresses)
.filter(address -> !currentActiveAddresses.contains(address))
.filter(contactAddresses::contains)
.toList();
recipientDatabase.setRegistered(activeAddresses, inactiveAddresses);
@ -127,6 +129,7 @@ public class DirectoryHelper {
RecipientDatabase recipientDatabase = DatabaseFactory.getRecipientDatabase(context);
SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(context);
boolean activeUser = recipient.resolve().getRegistered() == RegisteredState.REGISTERED;
boolean systemContact = recipient.isSystemContact();
String number = recipient.getAddress().serialize();
Optional<ContactTokenDetails> details = accountManager.getContact(number);
@ -141,7 +144,7 @@ public class DirectoryHelper {
ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceContactUpdateJob(context));
}
if (!activeUser) {
if (!activeUser && systemContact) {
notifyNewUsers(context, masterSecret, Collections.singletonList(recipient.getAddress()));
}