From b58c87a56b8f766e0bec1b87346fd9002f8e731e Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Thu, 7 Dec 2017 11:53:17 -0800 Subject: [PATCH] Only notify when address is in contacts --- .../securesms/database/RecipientDatabase.java | 13 +++++++++++++ .../securesms/util/DirectoryHelper.java | 7 +++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/RecipientDatabase.java b/src/org/thoughtcrime/securesms/database/RecipientDatabase.java index a8f8cb5efe..cd1883e934 100644 --- a/src/org/thoughtcrime/securesms/database/RecipientDatabase.java +++ b/src/org/thoughtcrime/securesms/database/RecipientDatabase.java @@ -354,6 +354,19 @@ public class RecipientDatabase extends Database { return results; } + public List
getSystemContacts() { + SQLiteDatabase db = databaseHelper.getReadableDatabase(); + List
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(); diff --git a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java index b66a6964b2..0aa2b911c4 100644 --- a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java +++ b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java @@ -67,7 +67,7 @@ public class DirectoryHelper { if (notifyOfNewUsers) notifyNewUsers(context, masterSecret, newlyActiveUsers); } - public static @NonNull List
refreshDirectory(@NonNull Context context, @NonNull SignalServiceAccountManager accountManager) + private static @NonNull List
refreshDirectory(@NonNull Context context, @NonNull SignalServiceAccountManager accountManager) throws IOException { if (TextUtils.isEmpty(TextSecurePreferences.getLocalNumber(context))) { @@ -101,8 +101,10 @@ public class DirectoryHelper { } Set
currentActiveAddresses = new HashSet<>(recipientDatabase.getRegistered()); + Set
contactAddresses = new HashSet<>(recipientDatabase.getSystemContacts()); List
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 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())); }