Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add experimental support for MSC3391: deleting account data #14714

Merged
merged 15 commits into from Jan 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion synapse/storage/databases/main/account_data.py
Expand Up @@ -123,7 +123,11 @@ def get_max_account_data_stream_id(self) -> int:
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.
Expand All @@ -142,6 +146,12 @@ def get_account_data_for_user_txn(
["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"] != "{}"]
clokep marked this conversation as resolved.
Show resolved Hide resolved

global_account_data = {
row["account_data_type"]: db_to_json(row["content"]) for row in rows
}
Expand All @@ -156,6 +166,16 @@ def get_account_data_for_user_txn(
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
Expand Down