diff options
author | David Robertson <davidr@element.io> | 2021-09-01 13:48:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-01 13:48:41 +0100 |
commit | d9069388f3aa22d548b4d51c069d42bd644b7ff4 (patch) | |
tree | f83392d52cece4d2b0ccb7fc240fa7cae09e7348 /synapse | |
parent | Skip the final GC on shutdown to improve restart times (#10712) (diff) | |
download | synapse-d9069388f3aa22d548b4d51c069d42bd644b7ff4.tar.xz |
Correctly include room avatars in email notifications (#10658)
Judging by the template, this was intended ages ago, but we never actually passed an avatar URL to the template. So let's provide one. Closes #1546. Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
Diffstat (limited to '')
-rw-r--r-- | synapse/push/mailer.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/synapse/push/mailer.py b/synapse/push/mailer.py index 941fb238b7..b0834720ad 100644 --- a/synapse/push/mailer.py +++ b/synapse/push/mailer.py @@ -258,7 +258,7 @@ class Mailer: # actually sort our so-called rooms_in_order list, most recent room first rooms_in_order.sort(key=lambda r: -(notifs_by_room[r][-1]["received_ts"] or 0)) - rooms = [] + rooms: List[Dict[str, Any]] = [] for r in rooms_in_order: roomvars = await self._get_room_vars( @@ -362,6 +362,7 @@ class Mailer: "notifs": [], "invite": is_invite, "link": self._make_room_link(room_id), + "avatar_url": await self._get_room_avatar(room_state_ids), } if not is_invite: @@ -393,6 +394,27 @@ class Mailer: return room_vars + async def _get_room_avatar( + self, + room_state_ids: StateMap[str], + ) -> Optional[str]: + """ + Retrieve the avatar url for this room---if it exists. + + Args: + room_state_ids: The event IDs of the current room state. + + Returns: + room's avatar url if it's present and a string; otherwise None. + """ + event_id = room_state_ids.get((EventTypes.RoomAvatar, "")) + if event_id: + ev = await self.store.get_event(event_id) + url = ev.content.get("url") + if isinstance(url, str): + return url + return None + async def _get_notif_vars( self, notif: Dict[str, Any], |