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

Commit

Permalink
Use account data constants in more places. (#15554)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed May 9, 2023
1 parent 6b7da31 commit 2bfe3f0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/15554.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use account data constants in more places.
1 change: 1 addition & 0 deletions synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class AccountDataTypes:
DIRECT: Final = "m.direct"
IGNORED_USER_LIST: Final = "m.ignored_user_list"
TAG: Final = "m.tag"
PUSH_RULES: Final = "m.push_rules"


class HistoryVisibility:
Expand Down
5 changes: 3 additions & 2 deletions synapse/handlers/read_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging
from typing import TYPE_CHECKING

from synapse.api.constants import ReceiptTypes
from synapse.util.async_helpers import Linearizer

if TYPE_CHECKING:
Expand Down Expand Up @@ -42,7 +43,7 @@ async def received_client_read_marker(

async with self.read_marker_linearizer.queue((room_id, user_id)):
existing_read_marker = await self.store.get_account_data_for_room_and_type(
user_id, room_id, "m.fully_read"
user_id, room_id, ReceiptTypes.FULLY_READ
)

should_update = True
Expand All @@ -56,5 +57,5 @@ async def received_client_read_marker(
if should_update:
content = {"event_id": event_id}
await self.account_data_handler.add_account_data_to_room(
user_id, room_id, "m.fully_read", content
user_id, room_id, ReceiptTypes.FULLY_READ, content
)
12 changes: 6 additions & 6 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1777,18 +1777,18 @@ async def _generate_sync_entry_for_account_data(

if push_rules_changed:
global_account_data = dict(global_account_data)
global_account_data["m.push_rules"] = await self.push_rules_for_user(
sync_config.user
)
global_account_data[
AccountDataTypes.PUSH_RULES
] = await self.push_rules_for_user(sync_config.user)
else:
all_global_account_data = await self.store.get_global_account_data_for_user(
user_id
)

global_account_data = dict(all_global_account_data)
global_account_data["m.push_rules"] = await self.push_rules_for_user(
sync_config.user
)
global_account_data[
AccountDataTypes.PUSH_RULES
] = await self.push_rules_for_user(sync_config.user)

account_data_for_user = (
await sync_config.filter_collection.filter_global_account_data(
Expand Down
3 changes: 2 additions & 1 deletion synapse/rest/client/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging
from typing import TYPE_CHECKING, Tuple

from synapse.api.constants import ReceiptTypes
from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError
from synapse.http.server import HttpServer
from synapse.http.servlet import RestServlet, parse_json_object_from_request
Expand Down Expand Up @@ -166,7 +167,7 @@ async def on_PUT(

body = parse_json_object_from_request(request)

if account_data_type == "m.fully_read":
if account_data_type == ReceiptTypes.FULLY_READ:
raise SynapseError(
405,
"Cannot set m.fully_read through this API."
Expand Down

0 comments on commit 2bfe3f0

Please sign in to comment.