From c850e33cda485e50373a2b859c61e10d297a9e76 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Fri, 29 Nov 2024 13:05:30 +0000 Subject: [PATCH] lint --- synapse/handlers/message.py | 7 ++++--- synapse/rest/client/room.py | 4 ++-- tests/rest/client/test_rooms.py | 17 +++++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 3accef0af9..ed10d50986 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -175,7 +175,7 @@ class MessageHandler: state_filter: Optional[StateFilter] = None, at_token: Optional[StreamToken] = None, last_hash: Optional[str] = None, - ) -> Tuple[List[dict], str]: + ) -> Tuple[List[dict], Optional[str]]: """Retrieve all state events for a given room. If the user is joined to the room then return the current state. If the user has left the room return the state events from when they left. If an explicit @@ -192,7 +192,8 @@ class MessageHandler: state based on the current_state_events table. Returns: A list of dicts representing state events. [{}, {}, {}] - A hash of the state IDs representing the state events. + A hash of the state IDs representing the state events. This is only calculated if + no at_token is given and the user is joined to the room. Raises: NotFoundError (404) if the at token does not yield an event @@ -250,7 +251,7 @@ class MessageHandler: # If the requester's hash matches ours, their cache is up to date and we can skip # fetching events. if last_hash == hash: - return None, hash + return [], hash room_state = await self.store.get_events(state_ids.values()) elif membership == Membership.LEAVE: # If the membership is not JOIN, then the event ID should exist. diff --git a/synapse/rest/client/room.py b/synapse/rest/client/room.py index 2f73df8b6e..302118919b 100644 --- a/synapse/rest/client/room.py +++ b/synapse/rest/client/room.py @@ -835,7 +835,7 @@ class RoomStateRestServlet(RestServlet): @cancellable async def on_GET( self, request: SynapseRequest, room_id: str - ) -> Tuple[int, List[JsonDict]]: + ) -> Tuple[int, Optional[List[JsonDict]]]: requester = await self.auth.get_user_by_req(request, allow_guest=True) existing_hash = request.getHeader(b"If-None-Match") @@ -848,7 +848,7 @@ class RoomStateRestServlet(RestServlet): ) request.setHeader(b"ETag", f'"{hash}"'.encode("ascii")) - if events is None: + if len(events) == 0: return 304, None return 200, events diff --git a/tests/rest/client/test_rooms.py b/tests/rest/client/test_rooms.py index c8976c203c..1523096d8e 100644 --- a/tests/rest/client/test_rooms.py +++ b/tests/rest/client/test_rooms.py @@ -560,21 +560,18 @@ class RoomStateTestCase(RoomBase): "/rooms/%s/state" % room_id, ) - etag = channel.headers.getRawHeaders(b"ETag")[0] + etagheader = channel.headers.getRawHeaders(b"ETag") self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.result["body"]) - self.assertIsNotNone( - etag, - "has a ETag header", - ) + assert etagheader channel2 = self.make_request( "GET", "/rooms/%s/state" % room_id, - custom_headers=( + custom_headers=[ ( b"If-None-Match", - etag, + etagheader[0], ), - ), + ], ) self.assertEqual( HTTPStatus.NOT_MODIFIED, @@ -582,8 +579,8 @@ class RoomStateTestCase(RoomBase): "Responds with not modified when provided with the correct ETag", ) self.assertEqual( - etag, - channel2.headers.getRawHeaders(b"ETag")[0], + etagheader, + channel2.headers.getRawHeaders(b"ETag"), "returns the same etag", )