mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-05 11:45:05 -04:00
Handle empty rooms when generating email notifications. (#9257)
Fixes some exceptions if the room state isn't quite as expected. If the expected state events aren't found, try to find them in the historical room state. If they still aren't found, fallback to a reasonable, although ugly, value.
This commit is contained in:
parent
2ab6e67ab7
commit
792263c97c
3 changed files with 226 additions and 39 deletions
|
@ -124,11 +124,16 @@ class EmailPusherTests(HomeserverTestCase):
|
|||
)
|
||||
self.helper.join(room=room, user=self.others[0].id, tok=self.others[0].token)
|
||||
|
||||
# The other user sends some messages
|
||||
# The other user sends a single message.
|
||||
self.helper.send(room, body="Hi!", tok=self.others[0].token)
|
||||
|
||||
# We should get emailed about that message
|
||||
self._check_for_mail()
|
||||
|
||||
# The other user sends multiple messages.
|
||||
self.helper.send(room, body="Hi!", tok=self.others[0].token)
|
||||
self.helper.send(room, body="There!", tok=self.others[0].token)
|
||||
|
||||
# We should get emailed about that message
|
||||
self._check_for_mail()
|
||||
|
||||
def test_invite_sends_email(self):
|
||||
|
@ -217,6 +222,45 @@ class EmailPusherTests(HomeserverTestCase):
|
|||
# We should get emailed about those messages
|
||||
self._check_for_mail()
|
||||
|
||||
def test_empty_room(self):
|
||||
"""All users leaving a room shouldn't cause the pusher to break."""
|
||||
# Create a simple room with two users
|
||||
room = self.helper.create_room_as(self.user_id, tok=self.access_token)
|
||||
self.helper.invite(
|
||||
room=room, src=self.user_id, tok=self.access_token, targ=self.others[0].id
|
||||
)
|
||||
self.helper.join(room=room, user=self.others[0].id, tok=self.others[0].token)
|
||||
|
||||
# The other user sends a single message.
|
||||
self.helper.send(room, body="Hi!", tok=self.others[0].token)
|
||||
|
||||
# Leave the room before the message is processed.
|
||||
self.helper.leave(room, self.user_id, tok=self.access_token)
|
||||
self.helper.leave(room, self.others[0].id, tok=self.others[0].token)
|
||||
|
||||
# We should get emailed about that message
|
||||
self._check_for_mail()
|
||||
|
||||
def test_empty_room_multiple_messages(self):
|
||||
"""All users leaving a room shouldn't cause the pusher to break."""
|
||||
# Create a simple room with two users
|
||||
room = self.helper.create_room_as(self.user_id, tok=self.access_token)
|
||||
self.helper.invite(
|
||||
room=room, src=self.user_id, tok=self.access_token, targ=self.others[0].id
|
||||
)
|
||||
self.helper.join(room=room, user=self.others[0].id, tok=self.others[0].token)
|
||||
|
||||
# The other user sends a single message.
|
||||
self.helper.send(room, body="Hi!", tok=self.others[0].token)
|
||||
self.helper.send(room, body="There!", tok=self.others[0].token)
|
||||
|
||||
# Leave the room before the message is processed.
|
||||
self.helper.leave(room, self.user_id, tok=self.access_token)
|
||||
self.helper.leave(room, self.others[0].id, tok=self.others[0].token)
|
||||
|
||||
# We should get emailed about that message
|
||||
self._check_for_mail()
|
||||
|
||||
def test_encrypted_message(self):
|
||||
room = self.helper.create_room_as(self.user_id, tok=self.access_token)
|
||||
self.helper.invite(
|
||||
|
@ -269,3 +313,6 @@ class EmailPusherTests(HomeserverTestCase):
|
|||
pushers = list(pushers)
|
||||
self.assertEqual(len(pushers), 1)
|
||||
self.assertTrue(pushers[0].last_stream_ordering > last_stream_ordering)
|
||||
|
||||
# Reset the attempts.
|
||||
self.email_attempts = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue