diff --git a/matrix_appservice_kakaotalk/kt/client/client.py b/matrix_appservice_kakaotalk/kt/client/client.py index 7ac9c7e..7ee83cb 100644 --- a/matrix_appservice_kakaotalk/kt/client/client.py +++ b/matrix_appservice_kakaotalk/kt/client/client.py @@ -215,13 +215,14 @@ class Client: channel_id=channel_id.serialize() ) - async def get_chats(self, channel_id: Long, limit: int | None, sync_from: Long | None) -> list[Chatlog]: - return (await self._api_user_request_result( + async def get_chats(self, channel_id: Long, sync_from: Long | None, limit: int | None) -> list[Chatlog]: + return await self._api_user_request_result( ResultListType(Chatlog), "get_chats", channel_id=channel_id.serialize(), - sync_from=sync_from.serialize() if sync_from else None - ))[-limit if limit else 0:] + sync_from=sync_from.serialize() if sync_from else None, + limit=limit + ) async def send_message(self, channel_id: Long, text: str) -> Chatlog: return await self._api_user_request_result( diff --git a/matrix_appservice_kakaotalk/portal.py b/matrix_appservice_kakaotalk/portal.py index 8ed18e1..1065890 100644 --- a/matrix_appservice_kakaotalk/portal.py +++ b/matrix_appservice_kakaotalk/portal.py @@ -941,8 +941,8 @@ class Portal(DBPortal, BasePortal): self.log.debug(f"Fetching {f'up to {limit}' if limit else 'all'} messages through {source.ktid}") messages = await source.client.get_chats( channel_info.channelId, - limit, - after_log_id + after_log_id, + limit ) if not messages: self.log.debug("Didn't get any messages from server") diff --git a/node/src/client.js b/node/src/client.js index 6320abd..6c203ac 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -339,12 +339,17 @@ export default class PeerClient { * @param {string} req.mxid * @param {Long} req.channel_id * @param {Long?} req.sync_from + * @param {Number?} req.limit */ getChats = async (req) => { const userClient = this.#getUser(req.mxid) const talkChannel = userClient.talkClient.channelList.get(req.channel_id) - return await talkChannel.getChatListFrom(req.sync_from) + const res = await talkChannel.getChatListFrom(req.sync_from) + if (res.success && 0 < req.limit && req.limit < res.result.length) { + res.result.splice(0, res.result.length - req.limit) + } + return res } /**