Support inbound channel adding, and log remaining events

Also use more consistent grammar for event log messages
This commit is contained in:
Andrew Ferrazzutti 2022-04-23 17:01:39 -04:00
parent 91af7890ac
commit db33378345
3 changed files with 60 additions and 6 deletions

View File

@ -515,6 +515,11 @@ class Client:
str(data["channelType"]),
)
def _on_channel_added(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_channel_added(
ChannelInfo.deserialize(data["channelInfo"]),
)
def _on_channel_join(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_channel_join(
ChannelInfo.deserialize(data["channelInfo"]),

View File

@ -58,6 +58,7 @@ METRIC_CHAT_READ = Summary("bridge_on_chat_read", "calls to on_chat_read")
METRIC_CHANNEL_META_CHANGE = Summary("bridge_on_channel_meta_change", "calls to on_channel_meta_change")
METRIC_PROFILE_CHANGE = Summary("bridge_on_profile_changed", "calls to on_profile_changed")
METRIC_PERM_CHANGE = Summary("bridge_on_perm_changed", "calls to on_perm_changed")
METRIC_CHANNEL_ADDED = Summary("bridge_on_channel_added", "calls to on_channel_added")
METRIC_CHANNEL_JOIN = Summary("bridge_on_channel_join", "calls to on_channel_join")
METRIC_CHANNEL_LEFT = Summary("bridge_on_channel_left", "calls to on_channel_left")
METRIC_CHANNEL_KICKED = Summary("bridge_on_channel_kicked", "calls to on_channel_kicked")
@ -790,10 +791,24 @@ class User(DBUser, BaseUser):
user_power_levels = await po.Portal.get_mapped_ktid_power_levels(user_id, power_level)
await portal.set_power_levels(user_power_levels)
@async_time(METRIC_CHANNEL_ADDED)
def on_channel_added(self, channel_info: ChannelInfo) -> Awaitable[None]:
return self._sync_channel(channel_info)
@async_time(METRIC_CHANNEL_JOIN)
async def on_channel_join(self, channel_info: ChannelInfo) -> None:
assert self.ktid
await self._sync_channel(channel_info)
portal = await po.Portal.get_by_ktid(
channel_info.channelId,
kt_receiver=self.ktid,
kt_type=channel_info.type,
)
if portal.mxid:
user = await pu.Puppet.get_by_ktid(self.ktid)
await portal.backfill_lock.wait("channel join")
await portal.handle_kakaotalk_user_join(self, user)
else:
await self._sync_channel(channel_info)
@async_time(METRIC_CHANNEL_LEFT)
async def on_channel_left(self, channel_id: Long, channel_type: ChannelType | None) -> None:

View File

@ -118,7 +118,7 @@ class UserClient {
this.peerClient = peerClient
this.#talkClient.on("chat", (data, channel) => {
this.log(`${data.chat.logId} received in channel ${channel.channelId}`)
this.log(`Chat ${data.chat.logId} received in channel ${channel.channelId}`)
this.write("chat", {
//is_sequential: true, // TODO Make sequential per user & channel (if it isn't already)
chatlog: data.chat,
@ -128,7 +128,7 @@ class UserClient {
})
this.#talkClient.on("chat_deleted", (feedChatlog, channel, feed) => {
this.log(`${feed.logId} deleted in channel ${channel.channelId} by user ${feedChatlog.sender.userId}`)
this.log(`Chat ${feed.logId} deleted in channel ${channel.channelId} by user ${feedChatlog.sender.userId}`)
this.write("chat_deleted", {
chatId: feed.logId,
senderId: feedChatlog.sender.userId,
@ -150,7 +150,7 @@ class UserClient {
})
this.#talkClient.on("chat_read", (chat, channel, reader) => {
this.log(`${chat.logId} read in channel ${channel.channelId} by ${reader.userId}`)
this.log(`Chat ${chat.logId} read in channel ${channel.channelId} by ${reader.userId}`)
this.write("chat_read", {
chatId: chat.logId,
senderId: reader.userId,
@ -159,8 +159,13 @@ class UserClient {
})
})
this.#talkClient.on("chat_event", (channel, author, type, count, chat) => {
// TODO Figure out if this is can ever be for anything other than hearts on Shouts
this.log(`Event ${type} (count = ${count}) on chat ${chat.logId} in channel ${channel.channelId} sent by user ${author.userId}`)
})
this.#talkClient.on("profile_changed", (channel, lastInfo, user) => {
this.log(`Profile of ${user.userId} changed (channel: ${channel ? channel.channelId : "None"})`)
this.log(`Profile of ${user.userId} changed (in channel ${channel ? channel.channelId : "None"})`)
this.write("profile_changed", {
info: user,
/* TODO Is this ever a per-channel profile change?
@ -182,6 +187,18 @@ class UserClient {
})
})
this.#talkClient.on("host_handover", (channel, lastLink, link) => {
// TODO Find how or if this relates to permissions
this.log(`Host of channel ${channel.channelId} changed from ${lastLink.linkOwner.nickname} to ${link.linkOwner.nickname}`)
})
this.#talkClient.on("channel_added", channel => {
this.log(`Added channel ${channel.channelId}`)
this.write("channel_added", {
channelInfo: channel.info,
})
})
this.#talkClient.on("channel_join", channel => {
this.log(`Joined channel ${channel.channelId}`)
this.write("channel_join", {
@ -198,7 +215,8 @@ class UserClient {
})
this.#talkClient.on("channel_kicked", (kickedLog, channel, feed) => {
this.log(`User ${feed.member.userId} kicked from channel ${channel.channelId} by user ${kickedLog.sender.userId}`)
// TODO Confirm whether this can refer to any user that was kicked, or only to the current user
this.log(`Kicked from channel ${channel.channelId}`)
this.write("channel_kicked", {
userId: feed.member.userId,
senderId: kickedLog.sender.userId,
@ -207,6 +225,21 @@ class UserClient {
})
})
this.#talkClient.on("channel_link_deleted", (feedChatLog, channel, feed) => {
// TODO Figure out what this means
this.log(`Channel link deleted in channel ${channel.channelId}: feed=${JSON.stringify(feed)}, feedChatLog=${JSON.stringify(feedChatLog)}`)
})
this.#talkClient.on("link_created", link => {
// TODO Figure out what this means
this.log(`Link created: ${JSON.stringify(link)}`)
})
this.#talkClient.on("link_deleted", link => {
// TODO Figure out what this means
this.log(`Link deleted: ${JSON.stringify(link)}`)
})
this.#talkClient.on("user_join", (joinLog, channel, user, feed) => {
this.log(`User ${user.userId} joined channel ${channel.channelId}`)
this.write("user_join", {
@ -226,6 +259,7 @@ class UserClient {
})
this.#talkClient.on("meta_change", (channel, type, newMeta) => {
// TODO Handle announcements as pinned messages
this.log(`Channel ${channel.channelId} metadata changed`)
})