feat(messages): stream history one-message-per-WS-frame instead of 50-row batch
- backend: add streamMany generator (paginated, yields one record at a time) + messagesService.streamMessages + WS 'stream_messages' handler emitting 'message_snapshot' per message, 'message_snapshot_end' with nextCursor - frontend: useMessagesStream hook accumulates snapshots into SWR list, SSR getMessages seeds first paint, WsHook gains sendText - add stream-many.test.ts locking the one-at-a-time + cursor contract
This commit is contained in:
@@ -99,3 +99,26 @@ export async function getRecordings(limit = 50): Promise<PaginatedRecordings> {
|
||||
limit,
|
||||
}) as unknown as Promise<PaginatedRecordings>;
|
||||
}
|
||||
|
||||
// ---- Messages (SSR seed for the streaming view) ----
|
||||
// Used to seed the first paint so the feed isn't blank before the WS stream
|
||||
// arrives. The client then takes over and streams the rest one frame at a time.
|
||||
export async function getMessages(
|
||||
guildId: string,
|
||||
channelId?: string,
|
||||
limit = 50,
|
||||
cursor?: string,
|
||||
): Promise<{
|
||||
data: import("@/lib/types").MessageRecord[];
|
||||
nextCursor: string | null;
|
||||
}> {
|
||||
return serverOrpc().messages.list({
|
||||
guildId,
|
||||
channelId,
|
||||
limit,
|
||||
cursor,
|
||||
}) as unknown as Promise<{
|
||||
data: import("@/lib/types").MessageRecord[];
|
||||
nextCursor: string | null;
|
||||
}>;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ export type WsHook = {
|
||||
eventType: E,
|
||||
handler: (data: unknown) => void,
|
||||
) => () => void;
|
||||
sendText: (text: string) => void;
|
||||
};
|
||||
|
||||
@@ -36,6 +36,13 @@ export interface WsEventMap {
|
||||
/** Gateway emits { id, deleted_at } — NOT a bare string */
|
||||
message_deleted: { id: string; deleted_at?: number };
|
||||
message_analyzed: MessageRecord;
|
||||
/**
|
||||
* Streamed history frame — one MessageRecord per WS message (replaces the old
|
||||
* 50-row batched `messages.list` fetch on the client). The view accumulates
|
||||
* these into the SWR list as they arrive. `message_snapshot_end` signals done.
|
||||
*/
|
||||
message_snapshot: MessageRecord;
|
||||
message_snapshot_end: { sent: number; error?: boolean };
|
||||
attachment_created: unknown;
|
||||
attachment_uploaded: unknown;
|
||||
voice_recording_started: unknown;
|
||||
|
||||
Reference in New Issue
Block a user