| 217 | |
| 218 | /** scan public groups one-by-one with random delay, fill chatCache */ |
| 219 | private async buildCache() { |
| 220 | try { |
| 221 | const cl = await getGlobalClient(); |
| 222 | if (!cl) return; |
| 223 | |
| 224 | const limit = this.configDb.data.cacheLimit; |
| 225 | // paginated getDialogs — respect cacheLimit > 100 |
| 226 | const all: any[] = []; |
| 227 | let offsetId = 0; |
| 228 | let offsetDate = 0; |
| 229 | let offsetPeer: any = new Api.InputPeerEmpty(); |
| 230 | while (all.length < limit) { |
| 231 | const page = (await cl.getDialogs({ offsetId, offsetDate, offsetPeer, limit: 100 })) as any[]; |
| 232 | if (!page.length) break; |
| 233 | for (const d of page) { |
| 234 | if (d.isGroup || d.isChat) all.push(d); |
| 235 | if (all.length >= limit) break; |
| 236 | } |
| 237 | if (page.length < 100) break; // last page |
| 238 | const last = page[page.length - 1]; |
| 239 | offsetId = last.dialog?.topMessage?.id ?? 0; |