Apply chat sync limit during RPC transfer

This commit is contained in:
Andrew Ferrazzutti 2022-03-12 23:26:23 -05:00
parent 4158788496
commit 1a947a1999
3 changed files with 13 additions and 7 deletions

View File

@ -215,13 +215,14 @@ class Client:
channel_id=channel_id.serialize() channel_id=channel_id.serialize()
) )
async def get_chats(self, channel_id: Long, limit: int | None, sync_from: Long | None) -> list[Chatlog]: async def get_chats(self, channel_id: Long, sync_from: Long | None, limit: int | None) -> list[Chatlog]:
return (await self._api_user_request_result( return await self._api_user_request_result(
ResultListType(Chatlog), ResultListType(Chatlog),
"get_chats", "get_chats",
channel_id=channel_id.serialize(), channel_id=channel_id.serialize(),
sync_from=sync_from.serialize() if sync_from else None sync_from=sync_from.serialize() if sync_from else None,
))[-limit if limit else 0:] limit=limit
)
async def send_message(self, channel_id: Long, text: str) -> Chatlog: async def send_message(self, channel_id: Long, text: str) -> Chatlog:
return await self._api_user_request_result( return await self._api_user_request_result(

View File

@ -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}") self.log.debug(f"Fetching {f'up to {limit}' if limit else 'all'} messages through {source.ktid}")
messages = await source.client.get_chats( messages = await source.client.get_chats(
channel_info.channelId, channel_info.channelId,
limit, after_log_id,
after_log_id limit
) )
if not messages: if not messages:
self.log.debug("Didn't get any messages from server") self.log.debug("Didn't get any messages from server")

View File

@ -339,12 +339,17 @@ export default class PeerClient {
* @param {string} req.mxid * @param {string} req.mxid
* @param {Long} req.channel_id * @param {Long} req.channel_id
* @param {Long?} req.sync_from * @param {Long?} req.sync_from
* @param {Number?} req.limit
*/ */
getChats = async (req) => { getChats = async (req) => {
const userClient = this.#getUser(req.mxid) const userClient = this.#getUser(req.mxid)
const talkChannel = userClient.talkClient.channelList.get(req.channel_id) 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
} }
/** /**