Notifications: format replies properly

This commit is contained in:
miruka 2020-09-16 20:58:02 -04:00
parent 4cd562e02f
commit 22e7dc7e8d
2 changed files with 17 additions and 3 deletions

View File

@ -337,6 +337,7 @@ class HTMLProcessor:
self._img_to_a,
self._remove_extra_newlines,
self._newlines_to_return_symbol if inline else lambda el: el,
self._reply_to_inline if inline else lambda el: el,
],
"element_postprocessors": [
self._font_color_to_span if outgoing else lambda el: el,
@ -458,6 +459,16 @@ class HTMLProcessor:
return el
def _reply_to_inline(self, el: HtmlElement) -> HtmlElement:
"""Turn <mx-reply> into a plaintext inline form."""
if el.tag != "mx-reply":
return el
el.tail = f" ⏎⏎ {el.tail or ''}"
return el
def _mentions_to_matrix_to_links(
self,
el: HtmlElement,

View File

@ -2230,10 +2230,13 @@ class MatrixClient(nio.AsyncClient):
body = f"{sender}: {item.inline_content}"
NotificationRequested(
title = room_name,
body = body.replace("", "<br>"),
high_importance = highlight,
image = await self.get_notification_avatar(
title = room_name,
body = body.replace("", "<br>")
.replace(" ⏎⏎ ", f"<br>{'' * 24}<br>"),
image = await self.get_notification_avatar(
mxc=item.sender_avatar, user_id=item.sender_id,
) if item.sender_avatar else "",
)