From 66f9a171118889c63477ebef275d82a335bfa044 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 20 May 2020 06:37:50 -0400 Subject: [PATCH] No need for origin_*body Event keys Also fixes lack of original message text when replying to non-message events. --- src/backend/matrix_client.py | 18 ++++++++---------- src/backend/models/items.py | 12 +++++------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index e82405ca..45e2a5bb 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -426,15 +426,19 @@ class MatrixClient(nio.AsyncClient): to: Event = \ self.models[self.user_id, room_id, "events"][reply_to_event_id] + source_body = getattr(to.source, "body", "") + content["format"] = "org.matrix.custom.html" - content["body"] = f"> <{to.sender_id}> {to.origin_body}" + content["body"] = f"> <{to.sender_id}> {source_body}" to_html = REPLY_FALLBACK.format( room_id = room_id, event_id = reply_to_event_id, user_id = to.sender_id, content = - to.origin_formatted_body or html.escape(to.origin_body), + getattr(to.source, "formatted_body", "") or + source_body or + html.escape(to.source.source["type"] if to.source else ""), reply_content = to_html, ) @@ -457,10 +461,8 @@ class MatrixClient(nio.AsyncClient): room_id, tx_id, event_type, - content = echo_body, - mentions = mentions, - origin_body = content["body"], - origin_formatted_body = content.get("formatted_body") or "", + content = echo_body, + mentions = mentions, ) await self._send_message(room_id, content, tx_id) @@ -697,7 +699,6 @@ class MatrixClient(nio.AsyncClient): transaction_id, event_type, inline_content = content["body"], - origin_body = content["body"], media_url = url, media_title = path.name, media_width = content["info"].get("w", 0), @@ -1437,9 +1438,6 @@ class MatrixClient(nio.AsyncClient): target_avatar = target_avatar, links = Event.parse_links(content), - origin_body = getattr(ev, "body", "") or "", - origin_formatted_body = getattr(ev, "formatted_body", "") or "", - fetch_profile = (must_fetch_sender or must_fetch_target) if override_fetch_profile is None else diff --git a/src/backend/models/items.py b/src/backend/models/items.py index f15a4fd5..665454dd 100644 --- a/src/backend/models/items.py +++ b/src/backend/models/items.py @@ -219,13 +219,11 @@ class Event(ModelItem): sender_avatar: str = field() fetch_profile: bool = False - origin_body: str = "" - origin_formatted_body: str = "" - content: str = "" - inline_content: str = "" - reason: str = "" - links: List[str] = field(default_factory=list) - mentions: List[Tuple[str, str]] = field(default_factory=list) + content: str = "" + inline_content: str = "" + reason: str = "" + links: List[str] = field(default_factory=list) + mentions: List[Tuple[str, str]] = field(default_factory=list) type_specifier: TypeSpecifier = TypeSpecifier.Unset