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