From fae003e085a074d2f13f30a510811dcda4ad232a Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Mon, 13 Jul 2020 11:52:06 -0300 Subject: [PATCH] Do not sync group v2 recipients that we do not have the master key for. --- .../securesms/database/RecipientDatabase.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java index a9fe6021a8..6334b560d0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.java @@ -804,8 +804,8 @@ public class RecipientDatabase extends Database { */ public @NonNull Map getContactStorageSyncIdsMap() { SQLiteDatabase db = databaseHelper.getReadableDatabase(); - String query = STORAGE_SERVICE_ID + " NOT NULL AND " + DIRTY + " != ? AND " + ID + " != ?"; - String[] args = new String[]{String.valueOf(DirtyState.DELETE), Recipient.self().getId().serialize() }; + String query = STORAGE_SERVICE_ID + " NOT NULL AND " + DIRTY + " != ? AND " + ID + " != ? AND " + GROUP_TYPE + " != ?"; + String[] args = { String.valueOf(DirtyState.DELETE), Recipient.self().getId().serialize(), String.valueOf(GroupType.SIGNAL_V2.getId()) }; Map out = new HashMap<>(); try (Cursor cursor = db.query(TABLE_NAME, new String[] { ID, STORAGE_SERVICE_ID, GROUP_TYPE }, query, args, null, null, null)) { @@ -818,12 +818,29 @@ public class RecipientDatabase extends Database { switch (groupType) { case NONE : out.put(id, StorageId.forContact(key)); break; case SIGNAL_V1 : out.put(id, StorageId.forGroupV1(key)); break; - case SIGNAL_V2 : out.put(id, StorageId.forGroupV2(key)); break; default : throw new AssertionError(); } } } + for (GroupId.V2 id : DatabaseFactory.getGroupDatabase(context).getAllGroupV2Ids()) { + Recipient recipient = Recipient.externalGroup(context, id); + RecipientId recipientId = recipient.getId(); + RecipientSettings recipientSettingsForSync = getRecipientSettingsForSync(recipientId); + + if (recipientSettingsForSync == null) { + throw new AssertionError(); + } + + byte[] key = recipientSettingsForSync.storageId; + + if (key == null) { + throw new AssertionError(); + } + + out.put(recipientId, StorageId.forGroupV2(key)); + } + return out; }