()
| 3862 | config: E2eConfig | undefined, |
| 3863 | ): Promise<RelayEvent[]> { |
| 3864 | const execute = async () => { |
| 3865 | const cap = Math.min(args.limitRows ?? 50, 200); |
| 3866 | const identity = getIdentity(config); |
| 3867 | |
| 3868 | if (!identity) { |
| 3869 | // Mock store: server-assembled channel window over the mock event store, |
| 3870 | // mirroring the relay path's shape so callers (parseChannelWindowResponse) |
| 3871 | // parse both modes identically. Top-level timeline rows in relay order, |
| 3872 | // then exactly one kind-39006 bounds event. |
| 3873 | const events = getMockMessageStore(args.channelId); |
| 3874 | const candidates = events |
| 3875 | .filter( |
| 3876 | (event) => TIMELINE_KINDS.has(event.kind) && isMockTopLevelRow(event), |
| 3877 | ) |
| 3878 | .sort( |
| 3879 | (left, right) => |
| 3880 | right.created_at - left.created_at || |
| 3881 | left.id.localeCompare(right.id), |
| 3882 | ); |
| 3883 | // Honor the composite (until, before_id) cursor exactly like the relay's |
| 3884 | // keyset: keep only rows strictly older than the cursor under the |
| 3885 | // (created_at DESC, id ASC) order — older created_at, or the same second |
| 3886 | // with a strictly greater id. |
| 3887 | const cursor = args.cursor; |
| 3888 | const afterCursor = cursor |
| 3889 | ? candidates.filter( |
| 3890 | (event) => |
| 3891 | event.created_at < cursor.created_at || |
| 3892 | (event.created_at === cursor.created_at && |
| 3893 | event.id > cursor.event_id), |
| 3894 | ) |
| 3895 | : candidates; |
| 3896 | const rows = afterCursor.slice(0, cap); |
| 3897 | // Exhaustion probe mirrors the relay's limit+1: more rows past the cursor |
| 3898 | // than the page cap means another page exists. next_cursor is the last |
| 3899 | // retained row. |
| 3900 | const hasMore = afterCursor.length > cap; |
| 3901 | const lastRow = rows[rows.length - 1]; |
| 3902 | const nextCursor = |
| 3903 | hasMore && lastRow |
| 3904 | ? { created_at: lastRow.created_at, id: lastRow.id } |
| 3905 | : null; |
| 3906 | const aux = buildMockChannelWindowAux(events, rows); |
| 3907 | const summaries = rows.flatMap((row) => { |
| 3908 | const summary = buildMockChannelThreadSummary( |
| 3909 | args.channelId, |
| 3910 | row, |
| 3911 | events, |
| 3912 | ); |
| 3913 | return summary ? [summary] : []; |
| 3914 | }); |
| 3915 | return [ |
| 3916 | ...rows, |
| 3917 | ...aux, |
| 3918 | ...summaries, |
| 3919 | buildMockChannelWindowBounds(args, hasMore, nextCursor), |
| 3920 | ]; |
| 3921 | } |
no test coverage detected