diff --git a/src/App.svelte b/src/App.svelte index 20dfd33..5e41b3d 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -17,6 +17,7 @@ let realtimeState = 'DISCONNECTED'; let realtimeSocket: WebSocket | undefined; let activityEvents: Array<{ event_id: string; event_type: string; occurred_at: string }> = []; + let chatMessages: Array<{ event_id: string; user_name: string; text: string; sent_at: string }> = []; let notifications: Array<{ id: string; severity: string; title: string; message: string; seen_at: string | null; created_at: string }> = []; let showNotifications = false; let showStreamEditor = false; @@ -144,6 +145,7 @@ notifications = []; showNotifications = false; diagnostics = undefined; + chatMessages = []; } function connectRealtime() { @@ -160,10 +162,13 @@ const event: { event_type?: string } = JSON.parse(message.data); if (event.event_type === 'connection.ready') realtimeState = 'CONNECTED'; else if ('event_id' in event && event.event_type) { - const activity = event as { event_id: string; event_type: string; occurred_at: string }; + const activity = event as { event_id: string; event_type: string; occurred_at: string; payload?: { chatter_user_name?: string; message?: { text?: string } } }; if (!activityEvents.some((item) => item.event_id === activity.event_id)) { activityEvents = [activity, ...activityEvents].slice(0, 100); } + if (activity.event_type === 'twitch.channel.chat.message' && activity.payload?.message?.text) { + chatMessages = [{ event_id: activity.event_id, user_name: activity.payload.chatter_user_name ?? 'unknown', text: activity.payload.message.text, sent_at: activity.occurred_at }, ...chatMessages].slice(0, 100); + } } } catch { realtimeState = 'DISCONNECTED'; @@ -185,6 +190,7 @@ }); if (!response.ok) return; activityEvents = await response.json(); + chatMessages = []; } catch { activityEvents = []; } @@ -451,7 +457,7 @@