From 4c205104a9572b21970a38f212654ed8526f58b2 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Sun, 10 Apr 2022 02:23:50 -0400 Subject: [PATCH] Inbound profile changes --- matrix_appservice_kakaotalk/kt/client/client.py | 7 +++++++ matrix_appservice_kakaotalk/user.py | 8 ++++++++ node/src/client.js | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/matrix_appservice_kakaotalk/kt/client/client.py b/matrix_appservice_kakaotalk/kt/client/client.py index d502ccc..387f434 100644 --- a/matrix_appservice_kakaotalk/kt/client/client.py +++ b/matrix_appservice_kakaotalk/kt/client/client.py @@ -44,6 +44,7 @@ from ..types.client.client_session import LoginResult from ..types.chat import Chatlog, KnownChatType from ..types.chat.attachment import MentionStruct, ReplyAttachment from ..types.oauth import OAuthCredential, OAuthInfo +from ..types.openlink.open_link_user_info import OpenLinkChannelUserInfo from ..types.packet.chat.kickout import KnownKickoutType, KickoutRes from ..types.request import ( deserialize_result, @@ -402,6 +403,11 @@ class Client: str(data["channelType"]), ) + async def _on_profile_changed(self, data: dict[str, JSON]) -> None: + await self.user.on_profile_changed( + OpenLinkChannelUserInfo.deserialize(data["info"]), + ) + """ TODO async def _on_receipt(self, data: Dict[str, JSON]) -> None: await self.user.on_receipt(Receipt.deserialize(data["receipt"])) @@ -430,6 +436,7 @@ class Client: def _start_listen(self) -> None: self._add_event_handler("chat", self._on_chat) self._add_event_handler("chat_deleted", self._on_chat_deleted) + self._add_event_handler("profile_changed", self._on_profile_changed) # TODO many more listeners self._add_event_handler("disconnected", self._on_listen_disconnect) self._add_event_handler("switch_server", self._on_switch_server) diff --git a/matrix_appservice_kakaotalk/user.py b/matrix_appservice_kakaotalk/user.py index 0a8d544..34e96a1 100644 --- a/matrix_appservice_kakaotalk/user.py +++ b/matrix_appservice_kakaotalk/user.py @@ -46,11 +46,13 @@ from .kt.types.chat.chat import Chatlog from .kt.types.client.client_session import LoginDataItem, LoginResult from .kt.types.oauth import OAuthCredential from .kt.types.openlink.open_channel_info import OpenChannelData, OpenChannelInfo +from .kt.types.openlink.open_link_user_info import OpenLinkChannelUserInfo from .kt.types.packet.chat.kickout import KnownKickoutType, KickoutRes METRIC_CONNECT_AND_SYNC = Summary("bridge_connect_and_sync", "calls to connect_and_sync") METRIC_CHAT = Summary("bridge_on_chat", "calls to on_chat") METRIC_CHAT_DELETED = Summary("bridge_on_chat_deleted", "calls to on_chat_deleted") +METRIC_PROFILE_CHANGE = Summary("bridge_on_profile_changed", "calls to on_profile_changed") METRIC_LOGGED_IN = Gauge("bridge_logged_in", "Users logged into the bridge") METRIC_CONNECTED = Gauge("bridge_connected", "Bridge users connected to KakaoTalk") @@ -701,6 +703,12 @@ class User(DBUser, BaseUser): puppet = await pu.Puppet.get_by_ktid(sender_id) await portal.handle_kakaotalk_chat_delete(puppet, chat_id, timestamp) + @async_time(METRIC_PROFILE_CHANGE) + async def on_profile_changed(self, info: OpenLinkChannelUserInfo) -> None: + puppet = await pu.Puppet.get_by_ktid(info.userId) + if puppet: + await puppet.update_info_from_participant(self, info) + # TODO Many more handlers # endregion diff --git a/node/src/client.js b/node/src/client.js index f791513..894346b 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -121,6 +121,17 @@ class UserClient { }) */ + this.#talkClient.on("profile_changed", (channel, lastInfo, user) => { + this.log(`Profile of ${user.userId} changed (channel: ${channel})`) + return this.write("profile_changed", { + info: user, + /* TODO Is this ever a per-channel profile change? + channelId: channel.channelId, + channelType: channel.info.type, + */ + }) + }) + this.#talkClient.on("disconnected", (reason) => { this.log(`Disconnected (reason=${reason})`) this.disconnect()