From a10a395e0b5dcf4e416e9a50cf69c990548f63ab Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 19 Jul 2019 18:13:04 -0400 Subject: [PATCH] Only send a formatted_body if it's truly needed --- TODO.md | 5 +++-- src/python/matrix_client.py | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/TODO.md b/TODO.md index 021169a7..99ca0db3 100644 --- a/TODO.md +++ b/TODO.md @@ -11,17 +11,19 @@ - Room Sidepane - When qml syntax highlighting supports string interpolation, use them -- Bug fixes +- Fixes - Past events loading (limit 100) freezes the GUI - need to move upsert func to a WorkerScript - `MessageDelegate.qml:63: TypeError: 'reloadPreviousItem' not a function` - Horrible performance for big rooms - UI + - Show error box if uploading avatar fails - EditAccount page: - Device settings - Multiaccount aliases: - Warn when overwriting another alias + - Forbid spaces? - Add an explanation tooltip - Improve avatar tooltips position, add stuff to room tooltips (last msg?) - Accept drag and dropping a picture in account settings to set avatar @@ -77,7 +79,6 @@ - Client improvements - Set Qt.application.* stuff from C++ - - Don't send a formatted_text if it's just `

plaintext

` - [debug mode](https://docs.python.org/3/library/asyncio-dev.html) - Initial sync filter and lazy load, see weechat-matrix `_handle_login()` - See also `handle_response()`'s `keys_query` request diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index 589cdfd9..86d1b94a 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -155,12 +155,12 @@ class MatrixClient(nio.AsyncClient): async def send_markdown(self, room_id: str, text: str) -> None: - content = { - "body": text, - "formatted_body": HTML_FILTER.from_markdown(text), - "format": "org.matrix.custom.html", - "msgtype": "m.text", - } + content = {"body": text, "msgtype": "m.text"} + to_html = HTML_FILTER.from_markdown(text) + + if to_html not in (text, f"

{text}

"): + content["format"] = "org.matrix.custom.html" + content["formatted_body"] = to_html TimelineMessageReceived( event_type = nio.RoomMessageText, @@ -168,7 +168,7 @@ class MatrixClient(nio.AsyncClient): event_id = f"local_echo.{uuid4()}", sender_id = self.user_id, date = datetime.now(), - content = content["formatted_body"], + content = to_html, is_local_echo = True, )