From fe6df88a4b081c2da7d7b196812f0736769200e9 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 12 Apr 2022 04:34:16 -0400 Subject: [PATCH] Return IDs of bridged outgoing messages instead of the chats themselves And set an optional property in AudioAttachment to be safe --- matrix_appservice_kakaotalk/kt/client/client.py | 8 ++++---- .../kt/types/chat/attachment/media.py | 5 +++-- matrix_appservice_kakaotalk/portal.py | 14 +++++++------- node/src/client.js | 10 ++++++---- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/matrix_appservice_kakaotalk/kt/client/client.py b/matrix_appservice_kakaotalk/kt/client/client.py index 54191de..2945e70 100644 --- a/matrix_appservice_kakaotalk/kt/client/client.py +++ b/matrix_appservice_kakaotalk/kt/client/client.py @@ -326,9 +326,9 @@ class Client: text: str, reply_to: ReplyAttachment | None, mentions: list[MentionStruct] | None, - ) -> Chatlog: + ) -> Long: return await self._api_user_request_result( - Chatlog, + Long, "send_chat", channel_props=channel_props.serialize(), text=text, @@ -346,9 +346,9 @@ class Client: width: int | None = None, height: int | None = None, ext: str | None = None, - ) -> Chatlog: + ) -> Long: return await self._api_user_request_result( - Chatlog, + Long, "send_media", channel_props=channel_props.serialize(), type=media_type, diff --git a/matrix_appservice_kakaotalk/kt/types/chat/attachment/media.py b/matrix_appservice_kakaotalk/kt/types/chat/attachment/media.py index ff54cad..50e7c4b 100644 --- a/matrix_appservice_kakaotalk/kt/types/chat/attachment/media.py +++ b/matrix_appservice_kakaotalk/kt/types/chat/attachment/media.py @@ -78,10 +78,11 @@ class FileAttachment(MediaKeyAttachment): @dataclass -class AudioAttachment(MediaKeyAttachment): - # NOTE Changed superclass from Attachment +class AudioAttachment(Attachment): + url: str d: int expire: Optional[int] = None + s: Optional[int] = None # NOTE Optional for inbound @dataclass diff --git a/matrix_appservice_kakaotalk/portal.py b/matrix_appservice_kakaotalk/portal.py index 8464396..9af624b 100644 --- a/matrix_appservice_kakaotalk/portal.py +++ b/matrix_appservice_kakaotalk/portal.py @@ -808,7 +808,7 @@ class Portal(DBPortal, BasePortal): async def _send_chat( self, sender: u.User, message: TextMessageEventContent, event_id: EventID | None = None - ) -> Chatlog: + ) -> Long: converted = await matrix_to_kakaotalk(message, self.mxid, self.log, self.main_intent) try: return await sender.client.send_chat( @@ -837,9 +837,9 @@ class Portal(DBPortal, BasePortal): async def _handle_matrix_text( self, event_id: EventID, sender: u.User, message: TextMessageEventContent ) -> None: - chatlog = await self._send_chat(sender, message, event_id) - await self._make_dbm(event_id, chatlog.logId) - self.log.debug(f"Handled Matrix message {event_id} -> {chatlog.logId}") + log_id = await self._send_chat(sender, message, event_id) + await self._make_dbm(event_id, log_id) + self.log.debug(f"Handled Matrix message {event_id} -> {log_id}") sender.send_remote_checkpoint( MessageSendCheckpointStatus.SUCCESS, event_id, @@ -867,7 +867,7 @@ class Portal(DBPortal, BasePortal): width = message.info.width height = message.info.height try: - chatlog = await sender.client.send_media( + log_id = await sender.client.send_media( self.channel_props, TO_MSGTYPE_MAP[message.msgtype], data, @@ -879,8 +879,8 @@ class Portal(DBPortal, BasePortal): except CommandException as e: self.log.debug(f"Error uploading media for Matrix message {event_id}: {e!s}") raise - await self._make_dbm(event_id, chatlog.logId) - self.log.debug(f"Handled Matrix message {event_id} -> {chatlog.logId}") + await self._make_dbm(event_id, log_id) + self.log.debug(f"Handled Matrix message {event_id} -> {log_id}") sender.send_remote_checkpoint( MessageSendCheckpointStatus.SUCCESS, event_id, diff --git a/node/src/client.js b/node/src/client.js index 088be0f..888358e 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -634,12 +634,13 @@ export default class PeerClient { */ sendChat = async (req) => { const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props) - - return await talkChannel.sendChat({ + const res = await talkChannel.sendChat({ text: req.text, type: !!req.reply_to ? KnownChatType.REPLY : KnownChatType.TEXT, attachment: !req.mentions ? req.reply_to : {...req.reply_to, mentions: req.mentions}, }) + if (res.success) res.result = res.result.logId + return res } /** @@ -655,14 +656,15 @@ export default class PeerClient { */ sendMedia = async (req) => { const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props) - - return await talkChannel.sendMedia(req.type, { + const res = await talkChannel.sendMedia(req.type, { data: Uint8Array.from(req.data), name: req.name, width: req.width, height: req.height, ext: req.ext, }) + if (res.success) res.result = res.result.logId + return res } /**