Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 6f33c1e

Browse files
committed
Share code between the single and multi-room cases.
This changes the behavior of the summary returned to be based on the number of senders, instead of based on the number of rooms.
1 parent 0b51f65 commit 6f33c1e

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

synapse/push/mailer.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -600,19 +600,10 @@ async def make_summary_text_single_room(
600600
"app": self.app_name,
601601
}
602602
else:
603-
# If the room doesn't have a name, say who the messages
604-
# are from explicitly to avoid, "messages in the Bob room"
605-
sender_ids = list({notif_events[n["event_id"]].sender for n in notifs})
606-
607-
member_events = await self.store.get_events(
608-
[room_state_ids[("m.room.member", s)] for s in sender_ids]
603+
return await self.make_summary_text_from_member_events(
604+
room_id, notifs, room_state_ids, notif_events
609605
)
610606

611-
return self.email_subjects.messages_from_person % {
612-
"person": descriptor_from_member_events(member_events.values()),
613-
"app": self.app_name,
614-
}
615-
616607
async def make_summary_text(
617608
self,
618609
notifs_by_room: Dict[str, List[Dict[str, Any]]],
@@ -640,23 +631,53 @@ async def make_summary_text(
640631
"app": self.app_name,
641632
}
642633
else:
643-
# If the reason room doesn't have a name, say who the messages
644-
# are from explicitly to avoid, "messages in the Bob room"
645634
room_id = reason["room_id"]
646635

647-
sender_ids = list(
648-
{notif_events[n["event_id"]].sender for n in notifs_by_room[room_id]}
636+
return await self.make_summary_text_from_member_events(
637+
room_id, notifs_by_room[room_id], room_state_ids[room_id], notif_events
649638
)
650639

651-
member_events = await self.store.get_events(
652-
[room_state_ids[room_id][("m.room.member", s)] for s in sender_ids]
653-
)
640+
async def make_summary_text_from_member_events(
641+
self,
642+
room_id: str,
643+
notifs: List[Dict[str, Any]],
644+
room_state_ids: StateMap[str],
645+
notif_events: Dict[str, EventBase],
646+
) -> str:
647+
"""
648+
Make a summary text for the email when only a single room has notifications.
654649
655-
return self.email_subjects.messages_from_person_and_others % {
650+
Args:
651+
room_id: The ID of the room.
652+
notifs: The notifications for this room.
653+
room_state_ids: The state map for the room.
654+
notif_events: A map of event ID -> notification event.
655+
656+
Returns:
657+
The summary text.
658+
"""
659+
# If the room doesn't have a name, say who the messages
660+
# are from explicitly to avoid, "messages in the Bob room"
661+
sender_ids = {notif_events[n["event_id"]].sender for n in notifs}
662+
663+
member_events = await self.store.get_events(
664+
[room_state_ids[("m.room.member", s)] for s in sender_ids]
665+
)
666+
667+
# There was a single sender.
668+
if len(sender_ids) == 1:
669+
return self.email_subjects.messages_from_person % {
656670
"person": descriptor_from_member_events(member_events.values()),
657671
"app": self.app_name,
658672
}
659673

674+
# There was more than one sender, use the first one and a tweaked template.
675+
else:
676+
return self.email_subjects.messages_from_person_and_others % {
677+
"person": descriptor_from_member_events(list(member_events.values())[:1]),
678+
"app": self.app_name,
679+
}
680+
660681
def make_room_link(self, room_id: str) -> str:
661682
if self.hs.config.email_riot_base_url:
662683
base_url = "%s/#/room" % (self.hs.config.email_riot_base_url)

0 commit comments

Comments
 (0)