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

Commit 2bfe3f0

Browse files
authored
Use account data constants in more places. (#15554)
1 parent 6b7da31 commit 2bfe3f0

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

changelog.d/15554.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use account data constants in more places.

synapse/api/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class AccountDataTypes:
257257
DIRECT: Final = "m.direct"
258258
IGNORED_USER_LIST: Final = "m.ignored_user_list"
259259
TAG: Final = "m.tag"
260+
PUSH_RULES: Final = "m.push_rules"
260261

261262

262263
class HistoryVisibility:

synapse/handlers/read_marker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import logging
1616
from typing import TYPE_CHECKING
1717

18+
from synapse.api.constants import ReceiptTypes
1819
from synapse.util.async_helpers import Linearizer
1920

2021
if TYPE_CHECKING:
@@ -42,7 +43,7 @@ async def received_client_read_marker(
4243

4344
async with self.read_marker_linearizer.queue((room_id, user_id)):
4445
existing_read_marker = await self.store.get_account_data_for_room_and_type(
45-
user_id, room_id, "m.fully_read"
46+
user_id, room_id, ReceiptTypes.FULLY_READ
4647
)
4748

4849
should_update = True
@@ -56,5 +57,5 @@ async def received_client_read_marker(
5657
if should_update:
5758
content = {"event_id": event_id}
5859
await self.account_data_handler.add_account_data_to_room(
59-
user_id, room_id, "m.fully_read", content
60+
user_id, room_id, ReceiptTypes.FULLY_READ, content
6061
)

synapse/handlers/sync.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,18 +1777,18 @@ async def _generate_sync_entry_for_account_data(
17771777

17781778
if push_rules_changed:
17791779
global_account_data = dict(global_account_data)
1780-
global_account_data["m.push_rules"] = await self.push_rules_for_user(
1781-
sync_config.user
1782-
)
1780+
global_account_data[
1781+
AccountDataTypes.PUSH_RULES
1782+
] = await self.push_rules_for_user(sync_config.user)
17831783
else:
17841784
all_global_account_data = await self.store.get_global_account_data_for_user(
17851785
user_id
17861786
)
17871787

17881788
global_account_data = dict(all_global_account_data)
1789-
global_account_data["m.push_rules"] = await self.push_rules_for_user(
1790-
sync_config.user
1791-
)
1789+
global_account_data[
1790+
AccountDataTypes.PUSH_RULES
1791+
] = await self.push_rules_for_user(sync_config.user)
17921792

17931793
account_data_for_user = (
17941794
await sync_config.filter_collection.filter_global_account_data(

synapse/rest/client/account_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import logging
1616
from typing import TYPE_CHECKING, Tuple
1717

18+
from synapse.api.constants import ReceiptTypes
1819
from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError
1920
from synapse.http.server import HttpServer
2021
from synapse.http.servlet import RestServlet, parse_json_object_from_request
@@ -166,7 +167,7 @@ async def on_PUT(
166167

167168
body = parse_json_object_from_request(request)
168169

169-
if account_data_type == "m.fully_read":
170+
if account_data_type == ReceiptTypes.FULLY_READ:
170171
raise SynapseError(
171172
405,
172173
"Cannot set m.fully_read through this API."

0 commit comments

Comments
 (0)