Skip to content

Add "default" account data feature #18407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
else:
self.max_event_delay_ms = None

self.account_data_defaults = config.get("account_data_defaults", {})

def has_tls_listener(self) -> bool:
return any(listener.is_tls() for listener in self.listeners)

Expand Down
3 changes: 0 additions & 3 deletions synapse/rest/client/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ async def on_GET(
user_id, account_data_type
)

if account_data is None:
raise NotFoundError("Account data not found")

# If experimental support for MSC3391 is enabled, then this endpoint should
# return a 404 if the content for an account data type is an empty dict.
if self._hs.config.experimental.msc3391_enabled and account_data == {}:
Expand Down
12 changes: 10 additions & 2 deletions synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def __init__(
self._delete_account_data_for_deactivated_users,
)

self.defaults = hs.config.server.account_data_defaults

def get_max_account_data_stream_id(self) -> int:
"""Get the current max stream ID for account data stream

Expand Down Expand Up @@ -149,11 +151,17 @@ def get_global_account_data_for_user(

txn.execute(sql, (user_id,))

return {
user_account_data = {
account_data_type: db_to_json(content)
for account_data_type, content in txn
}

for type, content in self.defaults.items():
if user_account_data.get(type) is None:
user_account_data[type] = content

return user_account_data

return await self.db_pool.runInteraction(
"get_global_account_data_for_user", get_global_account_data_for_user
)
Expand Down Expand Up @@ -225,7 +233,7 @@ async def get_global_account_data_by_type_for_user(
if result:
return db_to_json(result)
else:
return None
return self.defaults.get(data_type)

async def get_latest_stream_id_for_global_account_data_by_type_for_user(
self, user_id: str, data_type: str
Expand Down
Loading