@@ -600,19 +600,10 @@ async def make_summary_text_single_room(
600
600
"app" : self .app_name ,
601
601
}
602
602
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
609
605
)
610
606
611
- return self .email_subjects .messages_from_person % {
612
- "person" : descriptor_from_member_events (member_events .values ()),
613
- "app" : self .app_name ,
614
- }
615
-
616
607
async def make_summary_text (
617
608
self ,
618
609
notifs_by_room : Dict [str , List [Dict [str , Any ]]],
@@ -640,23 +631,53 @@ async def make_summary_text(
640
631
"app" : self .app_name ,
641
632
}
642
633
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"
645
634
room_id = reason ["room_id" ]
646
635
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
649
638
)
650
639
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.
654
649
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 % {
656
670
"person" : descriptor_from_member_events (member_events .values ()),
657
671
"app" : self .app_name ,
658
672
}
659
673
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
+
660
681
def make_room_link (self , room_id : str ) -> str :
661
682
if self .hs .config .email_riot_base_url :
662
683
base_url = "%s/#/room" % (self .hs .config .email_riot_base_url )
0 commit comments