summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2022-05-20 11:58:01 +0100
committerErik Johnston <erik@matrix.org>2022-05-20 12:07:37 +0100
commitd882ee6219aa1b2078141b3f4590f889680c7534 (patch)
tree984b1543f55a4f487fbd374d6380a623976b7406
parentUse helper function in auth (diff)
downloadsynapse-d882ee6219aa1b2078141b3f4590f889680c7534.tar.xz
Use helper function elsewhere
-rw-r--r--synapse/handlers/directory.py2
-rw-r--r--synapse/handlers/message.py4
-rw-r--r--synapse/handlers/room_member.py2
-rw-r--r--synapse/notifier.py2
-rw-r--r--synapse/rest/admin/rooms.py7
-rw-r--r--synapse/rest/client/room.py2
-rw-r--r--synapse/server_notices/resource_limits_server_notices.py4
-rw-r--r--tests/handlers/test_directory.py2
-rw-r--r--tests/storage/test_purge.py3
9 files changed, 15 insertions, 13 deletions
diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py
index 4aa33df884..f4730e6dcf 100644
--- a/synapse/handlers/directory.py
+++ b/synapse/handlers/directory.py
@@ -319,7 +319,7 @@ class DirectoryHandler:
         Raises:
             ShadowBanError if the requester has been shadow-banned.
         """
-        alias_event = await self.state.get_current_state(
+        alias_event = await self.store.get_current_state_event(
             room_id, EventTypes.CanonicalAlias, ""
         )
 
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index e566ff1f8e..f712e8cf75 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -117,7 +117,9 @@ class MessageHandler:
         )
 
         if membership == Membership.JOIN:
-            data = await self.state.get_current_state(room_id, event_type, state_key)
+            data = await self.store.get_current_state_event(
+                room_id, event_type, state_key
+            )
         elif membership == Membership.LEAVE:
             key = (event_type, state_key)
             # If the membership is not JOIN, then the event ID should exist.
diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py
index ea876c168d..8d6b255cf6 100644
--- a/synapse/handlers/room_member.py
+++ b/synapse/handlers/room_member.py
@@ -1805,7 +1805,7 @@ class RoomMemberMasterHandler(RoomMemberHandler):
     async def forget(self, user: UserID, room_id: str) -> None:
         user_id = user.to_string()
 
-        member = await self.state_handler.get_current_state(
+        member = await self.store.get_current_state_event(
             room_id=room_id, event_type=EventTypes.Member, state_key=user_id
         )
         membership = member.membership if member else None
diff --git a/synapse/notifier.py b/synapse/notifier.py
index ba23257f54..4a3bc492e7 100644
--- a/synapse/notifier.py
+++ b/synapse/notifier.py
@@ -681,7 +681,7 @@ class Notifier:
         return joined_room_ids, True
 
     async def _is_world_readable(self, room_id: str) -> bool:
-        state = await self.state_handler.get_current_state(
+        state = await self.store.get_current_state_event(
             room_id, EventTypes.RoomHistoryVisibility, ""
         )
         if state and "history_visibility" in state.content:
diff --git a/synapse/rest/admin/rooms.py b/synapse/rest/admin/rooms.py
index 356d6f74d7..b05bda04cb 100644
--- a/synapse/rest/admin/rooms.py
+++ b/synapse/rest/admin/rooms.py
@@ -447,7 +447,7 @@ class JoinRoomAliasServlet(ResolveRoomIdMixin, RestServlet):
         super().__init__(hs)
         self.auth = hs.get_auth()
         self.admin_handler = hs.get_admin_handler()
-        self.state_handler = hs.get_state_handler()
+        self.store = hs.get_datastores().main
         self.is_mine = hs.is_mine
 
     async def on_POST(
@@ -489,8 +489,9 @@ class JoinRoomAliasServlet(ResolveRoomIdMixin, RestServlet):
         )
 
         # send invite if room has "JoinRules.INVITE"
-        room_state = await self.state_handler.get_current_state(room_id)
-        join_rules_event = room_state.get((EventTypes.JoinRules, ""))
+        join_rules_event = await self.store.get_current_state_event(
+            room_id, EventTypes.JoinRules, ""
+        )
         if join_rules_event:
             if not (join_rules_event.content.get("join_rule") == JoinRules.PUBLIC):
                 # update_membership with an action of "invite" can raise a
diff --git a/synapse/rest/client/room.py b/synapse/rest/client/room.py
index 5a2361a2e6..dc8722067e 100644
--- a/synapse/rest/client/room.py
+++ b/synapse/rest/client/room.py
@@ -673,7 +673,7 @@ class RoomEventServlet(RestServlet):
         if include_unredacted_content and not await self.auth.is_server_admin(
             requester.user
         ):
-            power_level_event = await self._state.get_current_state(
+            power_level_event = await self._store.get_current_state_event(
                 room_id, EventTypes.PowerLevels, ""
             )
 
diff --git a/synapse/server_notices/resource_limits_server_notices.py b/synapse/server_notices/resource_limits_server_notices.py
index b5f3a0c74e..f904e39e27 100644
--- a/synapse/server_notices/resource_limits_server_notices.py
+++ b/synapse/server_notices/resource_limits_server_notices.py
@@ -178,8 +178,8 @@ class ResourceLimitsServerNotices:
         currently_blocked = False
         pinned_state_event = None
         try:
-            pinned_state_event = await self._state.get_current_state(
-                room_id, event_type=EventTypes.Pinned
+            pinned_state_event = await self._store.get_current_state_event(
+                room_id, event_type=EventTypes.Pinned, state_key=""
             )
         except AuthError:
             # The user has yet to join the server notices room
diff --git a/tests/handlers/test_directory.py b/tests/handlers/test_directory.py
index 11ad44223d..83a661c6b0 100644
--- a/tests/handlers/test_directory.py
+++ b/tests/handlers/test_directory.py
@@ -335,7 +335,7 @@ class CanonicalAliasTestCase(unittest.HomeserverTestCase):
     def _get_canonical_alias(self):
         """Get the canonical alias state of the room."""
         return self.get_success(
-            self.state_handler.get_current_state(
+            self.store.get_current_state_event(
                 self.room_id, EventTypes.CanonicalAlias, ""
             )
         )
diff --git a/tests/storage/test_purge.py b/tests/storage/test_purge.py
index 08cc60237e..5144f70af6 100644
--- a/tests/storage/test_purge.py
+++ b/tests/storage/test_purge.py
@@ -98,9 +98,8 @@ class PurgeTests(HomeserverTestCase):
         first = self.helper.send(self.room_id, body="test1")
 
         # Get the current room state.
-        state_handler = self.hs.get_state_handler()
         create_event = self.get_success(
-            state_handler.get_current_state(self.room_id, "m.room.create", "")
+            self.store.get_current_state_event(self.room_id, "m.room.create", "")
         )
         self.assertIsNotNone(create_event)