From 3dc1f2612e95676d6f3dd07a6a8226ac7e23b5ee Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 5 Apr 2022 00:59:22 -0400 Subject: [PATCH] Minor improvements --- .../kt/client/client.py | 2 +- node/src/client.js | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/matrix_appservice_kakaotalk/kt/client/client.py b/matrix_appservice_kakaotalk/kt/client/client.py index c12d744..701797a 100644 --- a/matrix_appservice_kakaotalk/kt/client/client.py +++ b/matrix_appservice_kakaotalk/kt/client/client.py @@ -276,7 +276,7 @@ class Client: async def send_message(self, channel_props: ChannelProps, text: str) -> Chatlog: return await self._api_user_request_result( Chatlog, - "send_message", + "send_chat", channel_props=channel_props.serialize(), text=text, ) diff --git a/node/src/client.js b/node/src/client.js index 61ac6e7..cb3004d 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -346,6 +346,14 @@ export default class PeerClient { return this.userClients.get(mxid) } + /** + * @param {string} mxid + * @param {Object} channel_props + */ + async #getUserChannel(mxid, channel_props) { + return await this.#getUser(mxid).getChannel(channel_props) + } + /** * @param {Object} req * @param {OAuthCredential} req.oauth_credential @@ -420,8 +428,7 @@ export default class PeerClient { * @param {Object} req.channel_props */ getPortalChannelInfo = async (req) => { - const userClient = this.#getUser(req.mxid) - const talkChannel = await userClient.getChannel(req.channel_props) + const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props) const res = await talkChannel.updateAll() if (!res.success) return res @@ -439,8 +446,7 @@ export default class PeerClient { * @param {Object} req.channel_props */ getParticipants = async (req) => { - const userClient = this.#getUser(req.mxid) - const talkChannel = await userClient.getChannel(req.channel_props) + const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props) return await talkChannel.getAllLatestUserInfo() } @@ -452,8 +458,7 @@ export default class PeerClient { * @param {?Number} req.limit */ getChats = async (req) => { - const userClient = this.#getUser(req.mxid) - const talkChannel = await userClient.getChannel(req.channel_props) + const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props) const res = await talkChannel.getChatListFrom(req.sync_from) if (res.success && 0 < req.limit && req.limit < res.result.length) { @@ -505,9 +510,8 @@ export default class PeerClient { * @param {Object} req.channel_props * @param {string} req.text */ - sendMessage = async (req) => { - const userClient = this.#getUser(req.mxid) - const talkChannel = await userClient.getChannel(req.channel_props) + sendChat = async (req) => { + const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props) return await talkChannel.sendChat({ type: KnownChatType.TEXT, @@ -527,8 +531,7 @@ export default class PeerClient { * @param {?string} req.ext */ sendMedia = async (req) => { - const userClient = this.#getUser(req.mxid) - const talkChannel = await userClient.getChannel(req.channel_props) + const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props) return await talkChannel.sendMedia(req.type, { data: Uint8Array.from(req.data), @@ -620,7 +623,7 @@ export default class PeerClient { list_friends: this.listFriends, get_friend_dm_id: req => this.getFriendProperty(req, "directChatId"), get_memo_ids: this.getMemoIds, - send_message: this.sendMessage, + send_chat: this.sendChat, send_media: this.sendMedia, }[req.command] || this.handleUnknownCommand }