| 1 | export interface TranscriptWindowPage { |
| 2 | entryIds: string[]; |
| 3 | olderCursor: string; |
| 4 | newerCursor: string; |
| 5 | appendable?: boolean; |
| 6 | } |
| 7 | |
| 8 | export function appendLivePageEntries(pages: TranscriptWindowPage[], entryIds: string[], pageSize: number): void { |
| 9 | for (let offset = 0; offset < entryIds.length;) { |
| 10 | const tail = pages[pages.length - 1]; |
| 11 | if (tail?.appendable && tail.entryIds.length < pageSize) { |
| 12 | const count = Math.min(pageSize - tail.entryIds.length, entryIds.length - offset); |
| 13 | tail.entryIds.push(...entryIds.slice(offset, offset + count)); |
| 14 | offset += count; |
| 15 | continue; |
| 16 | } |
| 17 | const page = entryIds.slice(offset, offset + pageSize); |
| 18 | pages.push({ entryIds: page, olderCursor: "", newerCursor: "", appendable: true }); |
| 19 | offset += page.length; |
| 20 | } |
| 21 | } |
| 22 |