0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-09-26 03:28:59 +02:00

Use account data constants in more places. (#15554)

This commit is contained in:
Patrick Cloke 2023-05-09 07:23:27 -04:00 committed by GitHub
parent 6b7da31221
commit 2bfe3f0b81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 9 deletions

1
changelog.d/15554.misc Normal file
View file

@ -0,0 +1 @@
Use account data constants in more places.

View file

@ -257,6 +257,7 @@ class AccountDataTypes:
DIRECT: Final = "m.direct" DIRECT: Final = "m.direct"
IGNORED_USER_LIST: Final = "m.ignored_user_list" IGNORED_USER_LIST: Final = "m.ignored_user_list"
TAG: Final = "m.tag" TAG: Final = "m.tag"
PUSH_RULES: Final = "m.push_rules"
class HistoryVisibility: class HistoryVisibility:

View file

@ -15,6 +15,7 @@
import logging import logging
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from synapse.api.constants import ReceiptTypes
from synapse.util.async_helpers import Linearizer from synapse.util.async_helpers import Linearizer
if TYPE_CHECKING: if TYPE_CHECKING:
@ -42,7 +43,7 @@ class ReadMarkerHandler:
async with self.read_marker_linearizer.queue((room_id, user_id)): async with self.read_marker_linearizer.queue((room_id, user_id)):
existing_read_marker = await self.store.get_account_data_for_room_and_type( 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 should_update = True
@ -56,5 +57,5 @@ class ReadMarkerHandler:
if should_update: if should_update:
content = {"event_id": event_id} content = {"event_id": event_id}
await self.account_data_handler.add_account_data_to_room( 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
) )

View file

@ -1777,18 +1777,18 @@ class SyncHandler:
if push_rules_changed: if push_rules_changed:
global_account_data = dict(global_account_data) global_account_data = dict(global_account_data)
global_account_data["m.push_rules"] = await self.push_rules_for_user( global_account_data[
sync_config.user AccountDataTypes.PUSH_RULES
) ] = await self.push_rules_for_user(sync_config.user)
else: else:
all_global_account_data = await self.store.get_global_account_data_for_user( all_global_account_data = await self.store.get_global_account_data_for_user(
user_id user_id
) )
global_account_data = dict(all_global_account_data) global_account_data = dict(all_global_account_data)
global_account_data["m.push_rules"] = await self.push_rules_for_user( global_account_data[
sync_config.user AccountDataTypes.PUSH_RULES
) ] = await self.push_rules_for_user(sync_config.user)
account_data_for_user = ( account_data_for_user = (
await sync_config.filter_collection.filter_global_account_data( await sync_config.filter_collection.filter_global_account_data(

View file

@ -15,6 +15,7 @@
import logging import logging
from typing import TYPE_CHECKING, Tuple from typing import TYPE_CHECKING, Tuple
from synapse.api.constants import ReceiptTypes
from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError
from synapse.http.server import HttpServer from synapse.http.server import HttpServer
from synapse.http.servlet import RestServlet, parse_json_object_from_request from synapse.http.servlet import RestServlet, parse_json_object_from_request
@ -166,7 +167,7 @@ class RoomAccountDataServlet(RestServlet):
body = parse_json_object_from_request(request) body = parse_json_object_from_request(request)
if account_data_type == "m.fully_read": if account_data_type == ReceiptTypes.FULLY_READ:
raise SynapseError( raise SynapseError(
405, 405,
"Cannot set m.fully_read through this API." "Cannot set m.fully_read through this API."