Inbound read receipts

But not while backfilling
This commit is contained in:
Andrew Ferrazzutti 2022-04-10 02:25:36 -04:00
parent 4c205104a9
commit 7b96687dae
4 changed files with 38 additions and 14 deletions

View File

@ -403,16 +403,19 @@ class Client:
str(data["channelType"]), str(data["channelType"]),
) )
async def _on_chat_read(self, data: dict[str, JSON]) -> None:
await self.user.on_chat_read(
Long.deserialize(data["chatId"]),
Long.deserialize(data["senderId"]),
Long.deserialize(data["channelId"]),
str(data["channelType"]),
)
async def _on_profile_changed(self, data: dict[str, JSON]) -> None: async def _on_profile_changed(self, data: dict[str, JSON]) -> None:
await self.user.on_profile_changed( await self.user.on_profile_changed(
OpenLinkChannelUserInfo.deserialize(data["info"]), OpenLinkChannelUserInfo.deserialize(data["info"]),
) )
""" TODO
async def _on_receipt(self, data: Dict[str, JSON]) -> None:
await self.user.on_receipt(Receipt.deserialize(data["receipt"]))
"""
async def _on_listen_disconnect(self, data: dict[str, JSON]) -> None: async def _on_listen_disconnect(self, data: dict[str, JSON]) -> None:
try: try:
res = KickoutRes.deserialize(data) res = KickoutRes.deserialize(data)
@ -436,8 +439,8 @@ class Client:
def _start_listen(self) -> None: def _start_listen(self) -> None:
self._add_event_handler("chat", self._on_chat) self._add_event_handler("chat", self._on_chat)
self._add_event_handler("chat_deleted", self._on_chat_deleted) self._add_event_handler("chat_deleted", self._on_chat_deleted)
self._add_event_handler("chat_read", self._on_chat_read)
self._add_event_handler("profile_changed", self._on_profile_changed) 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("disconnected", self._on_listen_disconnect)
self._add_event_handler("switch_server", self._on_switch_server) self._add_event_handler("switch_server", self._on_switch_server)
self._add_event_handler("error", self._on_error) self._add_event_handler("error", self._on_error)

View File

@ -527,8 +527,7 @@ class Portal(DBPortal, BasePortal):
if did_join and self.is_direct: if did_join and self.is_direct:
await source.update_direct_chats({self.main_intent.mxid: [self.mxid]}) await source.update_direct_chats({self.main_intent.mxid: [self.mxid]})
# TODO # TODO Sync read receipts?
#await self._sync_read_receipts(info.read_receipts.nodes)
""" """
async def _sync_read_receipts(self, receipts: list[None]) -> None: async def _sync_read_receipts(self, receipts: list[None]) -> None:
@ -702,8 +701,7 @@ class Portal(DBPortal, BasePortal):
except Exception: except Exception:
self.log.exception("Failed to backfill new portal") self.log.exception("Failed to backfill new portal")
# TODO # TODO Sync read receipts?
#await self._sync_read_receipts(info.read_receipts.nodes)
return self.mxid return self.mxid

View File

@ -52,6 +52,7 @@ from .kt.types.packet.chat.kickout import KnownKickoutType, KickoutRes
METRIC_CONNECT_AND_SYNC = Summary("bridge_connect_and_sync", "calls to connect_and_sync") 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 = Summary("bridge_on_chat", "calls to on_chat")
METRIC_CHAT_DELETED = Summary("bridge_on_chat_deleted", "calls to on_chat_deleted") METRIC_CHAT_DELETED = Summary("bridge_on_chat_deleted", "calls to on_chat_deleted")
METRIC_CHAT_READ = Summary("bridge_on_chat_read", "calls to on_chat_read")
METRIC_PROFILE_CHANGE = Summary("bridge_on_profile_changed", "calls to on_profile_changed") 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_LOGGED_IN = Gauge("bridge_logged_in", "Users logged into the bridge")
METRIC_CONNECTED = Gauge("bridge_connected", "Bridge users connected to KakaoTalk") METRIC_CONNECTED = Gauge("bridge_connected", "Bridge users connected to KakaoTalk")
@ -703,6 +704,25 @@ class User(DBUser, BaseUser):
puppet = await pu.Puppet.get_by_ktid(sender_id) puppet = await pu.Puppet.get_by_ktid(sender_id)
await portal.handle_kakaotalk_chat_delete(puppet, chat_id, timestamp) await portal.handle_kakaotalk_chat_delete(puppet, chat_id, timestamp)
@async_time(METRIC_CHAT_READ)
async def on_chat_read(
self,
chat_id: Long,
sender_id: Long,
channel_id: Long,
channel_type: ChannelType,
) -> None:
puppet = await pu.Puppet.get_by_ktid(sender_id)
portal = await po.Portal.get_by_ktid(
channel_id,
kt_receiver=self.ktid,
kt_type=channel_type,
create=False,
)
if portal and portal.mxid:
await portal.backfill_lock.wait(f"read receipt from {sender_id}")
await portal.handle_kakaotalk_read(self, puppet, chat_id)
@async_time(METRIC_PROFILE_CHANGE) @async_time(METRIC_PROFILE_CHANGE)
async def on_profile_changed(self, info: OpenLinkChannelUserInfo) -> None: async def on_profile_changed(self, info: OpenLinkChannelUserInfo) -> None:
puppet = await pu.Puppet.get_by_ktid(info.userId) puppet = await pu.Puppet.get_by_ktid(info.userId)

View File

@ -114,12 +114,15 @@ class UserClient {
}) })
}) })
/* TODO Many more listeners
this.#talkClient.on("chat_read", (chat, channel, reader) => { this.#talkClient.on("chat_read", (chat, channel, reader) => {
this.log(`chat_read in channel ${channel.channelId}`) this.log(`${chat.logId} read in channel ${channel.channelId} by ${reader.userId}`)
//chat.logId return this.write("chat_read", {
chatId: chat.logId,
senderId: reader.userId,
channelId: channel.channelId,
channelType: channel.info.type,
})
}) })
*/
this.#talkClient.on("profile_changed", (channel, lastInfo, user) => { this.#talkClient.on("profile_changed", (channel, lastInfo, user) => {
this.log(`Profile of ${user.userId} changed (channel: ${channel})`) this.log(`Profile of ${user.userId} changed (channel: ${channel})`)