Bypass chat cap when backfilling

This commit is contained in:
Andrew Ferrazzutti 2022-04-13 01:14:10 -04:00
parent ecb04fc2f5
commit 7a78d6ba25
1 changed files with 12 additions and 2 deletions

View File

@ -588,13 +588,23 @@ export default class PeerClient {
* @param {string} req.mxid
* @param {ChannelProps} req.channel_props
* @param {?Long} req.sync_from
* @param {?Number} req.limit
* @param {?number} req.limit
*/
getChats = async (req) => {
const talkChannel = await this.#getUserChannel(req.mxid, req.channel_props)
const res = await talkChannel.getChatListFrom(req.sync_from)
if (res.success && 0 < req.limit && req.limit < res.result.length) {
if (!res.success) return res
while (true) {
const nextRes = await talkChannel.getChatListFrom(
res.result[res.result.length - 1].logId
)
if (!nextRes.success) return nextRes
if (!nextRes.result.length) break
res.result.push(...nextRes.result)
}
if (0 < req.limit && req.limit < res.result.length) {
res.result.splice(0, res.result.length - req.limit)
}
return res