No need for origin_*body Event keys

Also fixes lack of original message text when
replying to non-message events.
This commit is contained in:
miruka 2020-05-20 06:37:50 -04:00
parent b09b3b990b
commit 66f9a17111
2 changed files with 13 additions and 17 deletions

View File

@ -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

View File

@ -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