Add read receipt handler that I forgot about

This commit is contained in:
Andrew Ferrazzutti 2022-04-11 04:26:21 -04:00
parent d44c843799
commit 383ea05432
3 changed files with 19 additions and 5 deletions

View File

@ -84,15 +84,15 @@ class Message:
@classmethod
async def get_closest_before(
cls, kt_chat: int, kt_receiver: int, timestamp: int
cls, kt_chat: int, kt_receiver: int, ktid: Long
) -> Message | None:
q = (
f"SELECT {cls.columns} "
"FROM message WHERE kt_chat=$1 AND kt_receiver=$2 AND timestamp<=$3 AND "
"FROM message WHERE kt_chat=$1 AND kt_receiver=$2 AND ktid<=$3 AND "
" ktid IS NOT NULL "
"ORDER BY timestamp DESC LIMIT 1"
"ORDER BY ktid DESC LIMIT 1"
)
row = await cls.db.fetchrow(q, kt_chat, kt_receiver, timestamp)
row = await cls.db.fetchrow(q, kt_chat, kt_receiver, ktid)
return cls._from_optional_row(row)
_insert_query = (

View File

@ -1277,6 +1277,20 @@ class Portal(DBPortal, BasePortal):
await self.main_intent.redact(message.mx_room, message.mxid, timestamp=timestamp)
await message.delete()
async def handle_kakaotalk_chat_read(self, source: u.User, sender: p.Puppet, chat_id: Long) -> None:
if not self.mxid:
return
msg = await DBMessage.get_closest_before(self.ktid, self.kt_receiver, chat_id)
if not msg:
return
if not await self._bridge_own_message_pm(source, sender, "read receipt", invite=False):
return
# NOTE No need for timestamp when the read receipt happened, since this is only for live ones
await sender.intent_for(self).mark_read(msg.mx_room, msg.mxid)
self.log.debug(
f"Handled KakaoTalk read receipt from {sender.ktid} up to {chat_id}/{msg.mxid}"
)
async def handle_kakaotalk_user_join(
self, source: u.User, user: p.Puppet
) -> None:

View File

@ -736,7 +736,7 @@ class User(DBUser, BaseUser):
)
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)
await portal.handle_kakaotalk_chat_read(self, puppet, chat_id)
@async_time(METRIC_PROFILE_CHANGE)
async def on_profile_changed(self, info: OpenLinkChannelUserInfo) -> None: