diff --git a/src/App.svelte b/src/App.svelte index 9215b76..7156117 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -15,6 +15,7 @@ let connectionNotice = ''; let realtimeState = 'DISCONNECTED'; let realtimeSocket: WebSocket | undefined; + let activityEvents: Array<{ event_id: string; event_type: string; occurred_at: string }> = []; let oauthLink = ''; let oauthIdentity: 'streamer' | 'bot' = 'streamer'; let oauthBusy = false; @@ -62,6 +63,7 @@ authenticated = true; mustReplaceCredentials = result.must_replace_credentials; connectionState = 'CONNECTED'; + await loadActivity(); connectRealtime(); if (!mustReplaceCredentials) password = ''; if (mustReplaceCredentials) newUsername = username; @@ -123,6 +125,12 @@ try { 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 }; + if (!activityEvents.some((item) => item.event_id === activity.event_id)) { + activityEvents = [activity, ...activityEvents].slice(0, 100); + } + } } catch { realtimeState = 'DISCONNECTED'; } @@ -136,6 +144,18 @@ }; } + async function loadActivity() { + try { + const response = await fetch(`${serverAddress}/api/v1/activity?limit=100`, { + headers: { authorization: `Bearer ${sessionToken}` }, + }); + if (!response.ok) return; + activityEvents = await response.json(); + } catch { + activityEvents = []; + } + } + async function createOAuthLink(identity: 'streamer' | 'bot') { oauthBusy = true; oauthError = ''; @@ -243,7 +263,7 @@ {:else}