Compare commits

...

2 Commits

5 changed files with 21 additions and 5 deletions

View File

@ -84,15 +84,15 @@ class Message:
@classmethod @classmethod
async def get_closest_before( 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: ) -> Message | None:
q = ( q = (
f"SELECT {cls.columns} " 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 " " 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) return cls._from_optional_row(row)
_insert_query = ( _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 self.main_intent.redact(message.mx_room, message.mxid, timestamp=timestamp)
await message.delete() 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( async def handle_kakaotalk_user_join(
self, source: u.User, user: p.Puppet self, source: u.User, user: p.Puppet
) -> None: ) -> None:

View File

@ -736,7 +736,7 @@ class User(DBUser, BaseUser):
) )
if portal and portal.mxid: if portal and portal.mxid:
await portal.backfill_lock.wait(f"read receipt from {sender_id}") 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_time(METRIC_PROFILE_CHANGE)
async def on_profile_changed(self, info: OpenLinkChannelUserInfo) -> None: async def on_profile_changed(self, info: OpenLinkChannelUserInfo) -> None:

View File

@ -10,6 +10,7 @@ NotifyAccess=all
WorkingDirectory=/opt/matrix-appservice-kakaotalk/node WorkingDirectory=/opt/matrix-appservice-kakaotalk/node
ConfigurationDirectory=matrix-appservice-kakaotalk ConfigurationDirectory=matrix-appservice-kakaotalk
RuntimeDirectory=matrix-appservice-kakaotalk RuntimeDirectory=matrix-appservice-kakaotalk
RuntimeDirectoryPreserve=yes
ExecStart=/usr/bin/env node src/main.js --config ${CONFIGURATION_DIRECTORY}/node-config.json ExecStart=/usr/bin/env node src/main.js --config ${CONFIGURATION_DIRECTORY}/node-config.json
Restart=on-failure Restart=on-failure
RestartSec=3 RestartSec=3

View File

@ -8,6 +8,7 @@ After=multi-user.target network.target
WorkingDirectory=/opt/matrix-appservice-kakaotalk WorkingDirectory=/opt/matrix-appservice-kakaotalk
ConfigurationDirectory=matrix-appservice-kakaotalk ConfigurationDirectory=matrix-appservice-kakaotalk
RuntimeDirectory=matrix-appservice-kakaotalk RuntimeDirectory=matrix-appservice-kakaotalk
RuntimeDirectoryPreserve=yes
ExecStart=/opt/matrix-appservice-kakaotalk/.venv/bin/python -m matrix_appservice_kakaotalk -c ${CONFIGURATION_DIRECTORY}/config.yaml ExecStart=/opt/matrix-appservice-kakaotalk/.venv/bin/python -m matrix_appservice_kakaotalk -c ${CONFIGURATION_DIRECTORY}/config.yaml
Restart=on-failure Restart=on-failure
RestartSec=3 RestartSec=3