From 22e7dc7e8d0b586440ff15e6f88251b78da39006 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 16 Sep 2020 20:58:02 -0400 Subject: [PATCH] Notifications: format replies properly --- src/backend/html_markdown.py | 11 +++++++++++ src/backend/matrix_client.py | 9 ++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/backend/html_markdown.py b/src/backend/html_markdown.py index 41ce3894..c9776316 100644 --- a/src/backend/html_markdown.py +++ b/src/backend/html_markdown.py @@ -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 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, diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 2912833e..4b6c07f6 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -2230,10 +2230,13 @@ class MatrixClient(nio.AsyncClient): body = f"{sender}: {item.inline_content}" NotificationRequested( - title = room_name, - body = body.replace(" ⏎ ", "
"), high_importance = highlight, - image = await self.get_notification_avatar( + title = room_name, + + body = body.replace(" ⏎ ", "
") + .replace(" ⏎⏎ ", f"
{'─' * 24}
"), + + image = await self.get_notification_avatar( mxc=item.sender_avatar, user_id=item.sender_id, ) if item.sender_avatar else "", )