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

Refactor email summary generation. #9260

Merged
merged 7 commits into from
Feb 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
clokep committed Jan 28, 2021
commit 6f33c1eb255039445ccd2de0fe3eaa07cbf71134
59 changes: 40 additions & 19 deletions synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,19 +600,10 @@ async def make_summary_text_single_room(
"app": self.app_name,
}
else:
# If the room doesn't have a name, say who the messages
# are from explicitly to avoid, "messages in the Bob room"
sender_ids = list({notif_events[n["event_id"]].sender for n in notifs})

member_events = await self.store.get_events(
[room_state_ids[("m.room.member", s)] for s in sender_ids]
return await self.make_summary_text_from_member_events(
room_id, notifs, room_state_ids, notif_events
)

return self.email_subjects.messages_from_person % {
"person": descriptor_from_member_events(member_events.values()),
"app": self.app_name,
}

async def make_summary_text(
self,
notifs_by_room: Dict[str, List[Dict[str, Any]]],
Expand Down Expand Up @@ -640,23 +631,53 @@ async def make_summary_text(
"app": self.app_name,
}
else:
# If the reason room doesn't have a name, say who the messages
# are from explicitly to avoid, "messages in the Bob room"
room_id = reason["room_id"]

sender_ids = list(
{notif_events[n["event_id"]].sender for n in notifs_by_room[room_id]}
return await self.make_summary_text_from_member_events(
room_id, notifs_by_room[room_id], room_state_ids[room_id], notif_events
)

member_events = await self.store.get_events(
[room_state_ids[room_id][("m.room.member", s)] for s in sender_ids]
)
async def make_summary_text_from_member_events(
self,
room_id: str,
notifs: List[Dict[str, Any]],
room_state_ids: StateMap[str],
notif_events: Dict[str, EventBase],
) -> str:
"""
Make a summary text for the email when only a single room has notifications.

return self.email_subjects.messages_from_person_and_others % {
Args:
room_id: The ID of the room.
notifs: The notifications for this room.
room_state_ids: The state map for the room.
notif_events: A map of event ID -> notification event.

Returns:
The summary text.
"""
# If the room doesn't have a name, say who the messages
# are from explicitly to avoid, "messages in the Bob room"
sender_ids = {notif_events[n["event_id"]].sender for n in notifs}

member_events = await self.store.get_events(
[room_state_ids[("m.room.member", s)] for s in sender_ids]
)

# There was a single sender.
if len(sender_ids) == 1:
return self.email_subjects.messages_from_person % {
"person": descriptor_from_member_events(member_events.values()),
"app": self.app_name,
}

# There was more than one sender, use the first one and a tweaked template.
else:
return self.email_subjects.messages_from_person_and_others % {
"person": descriptor_from_member_events(list(member_events.values())[:1]),
"app": self.app_name,
}

def make_room_link(self, room_id: str) -> str:
if self.hs.config.email_riot_base_url:
base_url = "%s/#/room" % (self.hs.config.email_riot_base_url)
Expand Down