From 9e831689e9519565cf423c14ac78ee8301f2a296 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 6 Nov 2019 22:49:26 +0200 Subject: [PATCH] Fix files over relaybot not having message format --- mautrix_telegram/commands/telegram/misc.py | 2 +- mautrix_telegram/portal/matrix.py | 23 +++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/mautrix_telegram/commands/telegram/misc.py b/mautrix_telegram/commands/telegram/misc.py index 6d9fde77..0e58685b 100644 --- a/mautrix_telegram/commands/telegram/misc.py +++ b/mautrix_telegram/commands/telegram/misc.py @@ -49,7 +49,7 @@ async def caption(evt: CommandEvent) -> EventID: if evt.content.format == Format.HTML: evt.content.formatted_body = evt.content.formatted_body.replace(prefix, "", 1) evt.content.body = evt.content.body.replace(prefix, "", 1) - evt.sender.command_status = {"caption": evt.content} + evt.sender.command_status = {"caption": evt.content, "action": "Caption"} return await evt.reply("Your next image or file will be sent with that caption. " "Use `$cmdprefix+sp cancel` to cancel the caption.") diff --git a/mautrix_telegram/portal/matrix.py b/mautrix_telegram/portal/matrix.py index 95c509e6..6aa0c8e1 100644 --- a/mautrix_telegram/portal/matrix.py +++ b/mautrix_telegram/portal/matrix.py @@ -360,18 +360,6 @@ class PortalMatrix(BasePortal, MautrixBasePortal, ABC): media = (MessageType.STICKER, MessageType.IMAGE, MessageType.FILE, MessageType.AUDIO, MessageType.VIDEO) - caption_content = None - if content.msgtype in media: - content["net.maunium.telegram.internal.filename"] = content.body - try: - caption_content: MessageEventContent = sender.command_status["caption"] - caption_content.msgtype = content.msgtype - reply_to = reply_to or formatter.matrix_reply_to_telegram(caption_content, space, - room_id=self.mxid) - sender.command_status = None - except (KeyError, TypeError): - pass - await self._pre_process_matrix_message(sender, not logged_in, caption_content or content) if content.msgtype == MessageType.NOTICE: bridge_notices = self.get_config("bridge_notices.default") @@ -385,6 +373,17 @@ class PortalMatrix(BasePortal, MautrixBasePortal, ABC): await self._handle_matrix_location(sender_id, event_id, space, client, content, reply_to) elif content.msgtype in media: + content["net.maunium.telegram.internal.filename"] = content.body + try: + caption_content: MessageEventContent = sender.command_status["caption"] + reply_to = reply_to or formatter.matrix_reply_to_telegram(caption_content, space, + room_id=self.mxid) + sender.command_status = None + except (KeyError, TypeError): + caption_content = None if logged_in else TextMessageEventContent(body=content.body) + if caption_content: + caption_content.msgtype = content.msgtype + await self._pre_process_matrix_message(sender, not logged_in, caption_content) await self._handle_matrix_file(sender_id, event_id, space, client, content, reply_to, caption_content) else: