From 4a68796fdfa5a7b2a830f7167cf9d14698ab9e5d Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Sun, 10 Apr 2022 04:26:09 -0400 Subject: [PATCH] Outbound read receipts --- .../kt/client/client.py | 11 ++++++++++ matrix_appservice_kakaotalk/matrix.py | 21 +++++++++---------- node/src/client.js | 14 +++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/matrix_appservice_kakaotalk/kt/client/client.py b/matrix_appservice_kakaotalk/kt/client/client.py index 6c4e268..444210c 100644 --- a/matrix_appservice_kakaotalk/kt/client/client.py +++ b/matrix_appservice_kakaotalk/kt/client/client.py @@ -355,6 +355,17 @@ class Client: chat_id=chat_id.serialize(), ) + async def mark_read( + self, + channel_props: ChannelProps, + read_until_chat_id: Long, + ) -> None: + return await self._api_user_request_void( + "mark_read", + channel_props=channel_props.serialize(), + read_until_chat_id=read_until_chat_id.serialize(), + ) + # TODO Combine these into one diff --git a/matrix_appservice_kakaotalk/matrix.py b/matrix_appservice_kakaotalk/matrix.py index 3f6e9eb..472df1b 100644 --- a/matrix_appservice_kakaotalk/matrix.py +++ b/matrix_appservice_kakaotalk/matrix.py @@ -24,6 +24,7 @@ from mautrix.types import ( EventType, ReactionEvent, ReactionEventContent, + ReceiptEvent, RedactionEvent, RelationType, RoomID, @@ -32,6 +33,7 @@ from mautrix.types import ( ) from . import portal as po, user as u +from .db import Message as DBMessage if TYPE_CHECKING: from .__main__ import KakaoTalkBridge @@ -153,19 +155,16 @@ class MatrixHandler(BaseMatrixHandler): event_id: EventID, data: SingleReceiptEventContent, ) -> None: - self.log.info("TODO: handle_read_receipt") - """ - if not user.mqtt: + if not user.is_connected: return - timestamp = data.get("ts", int(time.time() * 1000)) message = await DBMessage.get_by_mxid(event_id, portal.mxid) - await user.mqtt.mark_read( - portal.ktid, - True, # TODO - #portal.fb_type != ThreadType.USER, - read_to=message.timestamp if message else timestamp, - ) - """ + await user.client.mark_read(portal.channel_props, message.ktid) + + async def handle_ephemeral_event( + self, evt: ReceiptEvent | Event + ) -> None: + if evt.type == EventType.RECEIPT: + await self.handle_receipt(evt) async def handle_event(self, evt: Event) -> None: if evt.type == EventType.ROOM_REDACTION: diff --git a/node/src/client.js b/node/src/client.js index a74d8ca..0335885 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -605,6 +605,20 @@ export default class PeerClient { }) } + /** + * @param {Object} req + * @param {string} req.mxid + * @param {ChannelProps} req.channel_props + * @param {Long} req.read_until_chat_id + */ + markRead = async (req) => { + const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props) + + return await talkChannel.markRead({ + logId: req.read_until_chat_id, + }) + } + #makeCommandResult(result) { return { success: true,