mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-05 04:24:56 -04:00
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>
This commit is contained in:
parent
f8bf83b811
commit
d9069388f3
3 changed files with 71 additions and 6 deletions
|
@ -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],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue