diff --git a/mautrix/types/event/message.py b/mautrix/types/event/message.py index 30b1a153..32033581 100644 --- a/mautrix/types/event/message.py +++ b/mautrix/types/event/message.py @@ -119,7 +119,7 @@ def set_thread_parent( thread_parent.content.get_thread_parent() or self.relates_to.event_id ) if not disable_reply_fallback: - self.set_reply(last_event_in_thread or thread_parent, disable_fallback=True, **kwargs) + self.set_reply(last_event_in_thread or thread_parent, **kwargs) self.relates_to.is_falling_back = True def set_edit(self, edits: Union[EventID, "MessageEvent"]) -> None: @@ -287,25 +287,6 @@ class TextMessageEventContent(BaseMessageEventContent, SerializableAttrs): format: Format = None formatted_body: str = None - def set_reply( - self, - reply_to: Union["MessageEvent", EventID], - *, - displayname: Optional[str] = None, - disable_fallback: bool = False, - ) -> None: - super().set_reply(reply_to) - if isinstance(reply_to, str): - return - if isinstance(reply_to, MessageEvent) and not disable_fallback: - self.ensure_has_html() - if isinstance(reply_to.content, TextMessageEventContent): - reply_to.content.trim_reply_fallback() - self.formatted_body = ( - reply_to.make_reply_fallback_html(displayname) + self.formatted_body - ) - self.body = reply_to.make_reply_fallback_text(displayname) + self.body - def ensure_has_html(self) -> None: if not self.formatted_body or self.format != Format.HTML: self.format = Format.HTML @@ -424,36 +405,3 @@ def deserialize_content(data: JSON) -> MessageEventContent: return LocationMessageEventContent.deserialize(data) else: return Obj(**data) - - def make_reply_fallback_html(self, displayname: Optional[str] = None) -> str: - """Generate the HTML fallback for messages replying to this event.""" - if self.content.msgtype.is_text: - body = self.content.formatted_body or escape(self.content.body).replace("\n", "
") - else: - sent_type = media_reply_fallback_body_map[self.content.msgtype] or "a message" - body = f"sent {sent_type}" - displayname = escape(displayname) if displayname else self.sender - return html_reply_fallback_format.format( - room_id=self.room_id, - event_id=self.event_id, - sender=self.sender, - displayname=displayname, - content=body, - ) - - def make_reply_fallback_text(self, displayname: Optional[str] = None) -> str: - """Generate the plaintext fallback for messages replying to this event.""" - if self.content.msgtype.is_text: - body = self.content.body - else: - try: - body = media_reply_fallback_body_map[self.content.msgtype] - except KeyError: - body = "an unknown message type" - lines = body.strip().split("\n") - first_line, lines = lines[0], lines[1:] - fallback_text = f"> <{displayname or self.sender}> {first_line}" - for line in lines: - fallback_text += f"\n> {line}" - fallback_text += "\n\n" - return fallback_text