(input: {
channelName: string;
count: number;
startIndex?: number;
lineCount?: number;
createdAtStart?: number;
emit?: boolean;
})
| 3075 | } |
| 3076 | |
| 3077 | function prependMockHistory(input: { |
| 3078 | channelName: string; |
| 3079 | count: number; |
| 3080 | startIndex?: number; |
| 3081 | lineCount?: number; |
| 3082 | createdAtStart?: number; |
| 3083 | emit?: boolean; |
| 3084 | }) { |
| 3085 | const channel = mockChannels.find( |
| 3086 | (candidate) => candidate.name === input.channelName, |
| 3087 | ); |
| 3088 | if (!channel) { |
| 3089 | throw new Error(`Unknown mock channel: ${input.channelName}`); |
| 3090 | } |
| 3091 | |
| 3092 | const store = getMockMessageStore(channel.id); |
| 3093 | const earliestCreatedAt = store.reduce( |
| 3094 | (earliest, event) => Math.min(earliest, event.created_at), |
| 3095 | Math.floor(Date.now() / 1000), |
| 3096 | ); |
| 3097 | const createdAtStart = |
| 3098 | input.createdAtStart ?? earliestCreatedAt - input.count - 1; |
| 3099 | const startIndex = input.startIndex ?? 0; |
| 3100 | const lineCount = input.lineCount ?? 1; |
| 3101 | |
| 3102 | const events = Array.from({ length: input.count }, (_, offset) => { |
| 3103 | const index = startIndex + offset; |
| 3104 | const body = Array.from( |
| 3105 | { length: lineCount }, |
| 3106 | (_unused, lineIndex) => `mock older ${index} line ${lineIndex + 1}`, |
| 3107 | ).join("\n"); |
| 3108 | |
| 3109 | return createMockEvent( |
| 3110 | 9, |
| 3111 | body, |
| 3112 | [["h", channel.id]], |
| 3113 | ALICE_PUBKEY, |
| 3114 | createdAtStart + offset, |
| 3115 | `mock-older-${channel.name}-${index}`.replace(/[^a-zA-Z0-9]/g, ""), |
| 3116 | ); |
| 3117 | }); |
| 3118 | |
| 3119 | store.unshift(...events); |
| 3120 | store.sort((left, right) => left.created_at - right.created_at); |
| 3121 | |
| 3122 | if (input.emit) { |
| 3123 | for (const event of events) { |
| 3124 | emitMockLiveEvent(channel.id, event); |
| 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | return events; |
| 3129 | } |
| 3130 | |
| 3131 | function emitMockHistory( |
| 3132 | socket: MockSocket, |
nothing calls this directly
no test coverage detected