From 8e35bfc8895e2cfdc040d2476fb5f3e82efa92a4 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 16 Nov 2022 18:27:51 +0000 Subject: Prevent deleted account data items appearing in initial syncs --- synapse/storage/databases/main/account_data.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/account_data.py b/synapse/storage/databases/main/account_data.py index a11be64755..3e2c3191c8 100644 --- a/synapse/storage/databases/main/account_data.py +++ b/synapse/storage/databases/main/account_data.py @@ -123,7 +123,11 @@ class AccountDataWorkerStore(PushRulesWorkerStore, CacheInvalidationWorkerStore) async def get_account_data_for_user( self, user_id: str ) -> Tuple[Dict[str, JsonDict], Dict[str, Dict[str, JsonDict]]]: - """Get all the client account_data for a user. + """ + Get all the client account_data for a user. + + If experimental MSC3391 support is enabled, any entries with an empty + content body are excluded; as this means they have been deleted. Args: user_id: The user to get the account_data for. @@ -142,6 +146,12 @@ class AccountDataWorkerStore(PushRulesWorkerStore, CacheInvalidationWorkerStore) ["account_data_type", "content"], ) + # If experimental MSC3391 support is enabled, then account data entries + # with an empty content are considered "deleted". So skip adding them to + # the results. + if self.hs.config.experimental.msc3391_enabled: + rows = [row for row in rows if row["content"] != "{}"] + global_account_data = { row["account_data_type"]: db_to_json(row["content"]) for row in rows } @@ -156,6 +166,16 @@ class AccountDataWorkerStore(PushRulesWorkerStore, CacheInvalidationWorkerStore) by_room: Dict[str, Dict[str, JsonDict]] = {} for row in rows: room_data = by_room.setdefault(row["room_id"], {}) + + # If experimental MSC3391 support is enabled, then account data entries + # with an empty content are considered "deleted". So skip adding them to + # the results. + if ( + self.hs.config.experimental.msc3391_enabled + and row["content"] == "{}" + ): + continue + room_data[row["account_data_type"]] = db_to_json(row["content"]) return global_account_data, by_room -- cgit 1.4.1