From 4e8dbd60071b6f69adba7fe394838a8668bdfbbe Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Wed, 29 Jan 2025 16:58:56 -0800 Subject: [PATCH] lint + tests --- synapse/handlers/message.py | 2 +- synapse/storage/databases/main/roommember.py | 5 +++-- tests/rest/client/test_rooms.py | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 0a1ecdf5616..b4cee395f0b 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -1441,7 +1441,7 @@ async def handle_new_client_event( return prev_event if event.type == "m.room.message" or event.type == "m.room.encrypted": - await self.store.set_room_participation(event.room_id, event.user_id) + await self.store.set_room_participation(event.user_id, event.room_id) if event.internal_metadata.is_out_of_band_membership(): # the only sort of out-of-band-membership events we expect to see here are diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index 7ab879fc134..cd27474dc71 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -1705,7 +1705,7 @@ async def _populate_participant(self, progress: JsonDict, batch_size: int) -> in """ stream_token = progress.get("last_stream_token", None) - def _get_max_stream_token_txn(txn: LoggingTransaction) -> Optional[str]: + def _get_max_stream_token_txn(txn: LoggingTransaction) -> Optional[int]: sql = """ SELECT event_stream_ordering from room_memberships ORDER BY event_stream_ordering DESC @@ -1713,7 +1713,8 @@ def _get_max_stream_token_txn(txn: LoggingTransaction) -> Optional[str]: """ txn.execute(sql) res = txn.fetchone() - assert res is not None + if not res: + return 0 return res[0] def _background_populate_participant_txn( diff --git a/tests/rest/client/test_rooms.py b/tests/rest/client/test_rooms.py index ba0ff4d0451..4230bb58069 100644 --- a/tests/rest/client/test_rooms.py +++ b/tests/rest/client/test_rooms.py @@ -4102,7 +4102,7 @@ def test_sending_message_records_participation(self) -> None: # user has not sent any messages, so should not be a participant participant = self.get_success( - self.store.get_room_participation(self.room1, self.user2) + self.store.get_room_participation(self.user2, self.room1) ) self.assertFalse(participant) @@ -4117,7 +4117,7 @@ def test_sending_message_records_participation(self) -> None: tok=self.tok2, ) participant = self.get_success( - self.store.get_room_participation(self.room1, self.user2) + self.store.get_room_participation(self.user2, self.room1) ) self.assertTrue(participant) @@ -4130,7 +4130,7 @@ def test_sending_encrypted_event_records_participation(self) -> None: # user has not sent any messages, so should not be a participant participant = self.get_success( - self.store.get_room_participation(self.room1, self.user2) + self.store.get_room_participation(self.user2, self.room1) ) self.assertFalse(participant) @@ -4148,6 +4148,6 @@ def test_sending_encrypted_event_records_participation(self) -> None: tok=self.tok2, ) participant = self.get_success( - self.store.get_room_participation(self.room1, self.user2) + self.store.get_room_participation(self.user2, self.room1) ) self.assertTrue(participant)