-
Notifications
You must be signed in to change notification settings - Fork 1
chore: add logging to 7tv cosmetics flow #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
34168d2
b6dbb8a
4d923b5
a63ec74
a73392c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -551,7 +551,9 @@ const useChatStore = create((set, get) => ({ | |
|
|
||
| if (stvPresenceUpdates.has(userId)) { | ||
| const lastUpdateTime = stvPresenceUpdates.get(userId); | ||
| console.log("[7tv Presence]: Last update time for chatroom:", userId, lastUpdateTime, stvPresenceUpdates); | ||
| if (window.__KT_TELEMETRY_UTILS__?.shouldLogDebug?.()) { | ||
| console.log("[7tv Presence]: Last update time for chatroom:", userId, lastUpdateTime, stvPresenceUpdates); | ||
| } | ||
| if (currentTime - lastUpdateTime < PRESENCE_UPDATE_INTERVAL) { | ||
| return; | ||
| } | ||
|
|
@@ -1225,6 +1227,24 @@ const useChatStore = create((set, get) => ({ | |
| if (pusher.chat.OPEN) { | ||
| const channel7TVEmotes = await window.app.stv.getChannelEmotes(chatroom.streamerData.user_id); | ||
|
|
||
| // Load initial cosmetics (badges and paints) for the channel | ||
| try { | ||
| const channelCosmetics = await window.app.stv.getChannelCosmetics(chatroom.streamerData.user_id); | ||
| console.log('[7TV Cosmetics] Initial cosmetics loaded:', { | ||
| badges: channelCosmetics?.badges?.length || 0, | ||
| paints: channelCosmetics?.paints?.length || 0 | ||
| }); | ||
|
|
||
| // Add cosmetics to the store | ||
| const addCosmetics = useCosmeticsStore?.getState()?.addCosmetics; | ||
| if (addCosmetics && channelCosmetics && (channelCosmetics.badges?.length > 0 || channelCosmetics.paints?.length > 0)) { | ||
| addCosmetics(channelCosmetics); | ||
| console.log('[7TV Cosmetics] Added initial cosmetics to store'); | ||
| } | ||
| } catch (error) { | ||
| console.error('[7TV Cosmetics] Failed to load initial cosmetics:', error); | ||
| } | ||
|
|
||
| if (channel7TVEmotes) { | ||
| const seenEmoteNames = new Set(); | ||
|
|
||
|
|
@@ -1509,14 +1529,21 @@ const useChatStore = create((set, get) => ({ | |
| // 7TV event handlers | ||
| onStvMessage: (event) => { | ||
| try { | ||
| const { chatroomId } = event.detail; | ||
| const { chatroomId, type, body } = event.detail; | ||
| if (chatroomId) { | ||
| get().handleStvMessage(chatroomId, event.detail); | ||
| } else { | ||
| // Broadcast to all chatrooms if no specific chatroom | ||
| chatrooms.forEach(chatroom => { | ||
| get().handleStvMessage(chatroom.id, event.detail); | ||
| }); | ||
| // Handle global cosmetic events once instead of broadcasting to all chatrooms | ||
| if (type === 'cosmetic.create' || type === 'entitlement.create' || type === 'entitlement.delete') { | ||
| console.log(`[ChatProvider] Processing global ${type} event for ${body?.object?.user?.username || 'unknown'}`); | ||
| // Handle once with a null chatroomId to indicate global event | ||
| get().handleStvMessage(null, event.detail); | ||
| } else { | ||
| // Broadcast to all chatrooms if no specific chatroom (for non-cosmetic events) | ||
| chatrooms.forEach(chatroom => { | ||
| get().handleStvMessage(chatroom.id, event.detail); | ||
| }); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.error("[ChatProvider] Error handling 7TV message:", error); | ||
|
|
@@ -1625,7 +1652,9 @@ const useChatStore = create((set, get) => ({ | |
| get().connectToChatroom(chatroom); | ||
|
|
||
| // Connect to 7TV WebSocket | ||
| get().connectToStvWebSocket(chatroom); | ||
| // DISABLED: Using shared connection system via connectionManager.initializeConnections | ||
| console.log(`[ChatProvider] Skipping individual 7TV connection for chatroom ${chatroom.id} - using shared connection system`); | ||
| // get().connectToStvWebSocket(chatroom); | ||
| } | ||
| }); | ||
| }, | ||
|
|
@@ -1893,19 +1922,79 @@ const useChatStore = create((set, get) => ({ | |
| handleStvMessage: (chatroomId, eventDetail) => { | ||
| const { type, body } = eventDetail; | ||
|
|
||
| console.log( | ||
| `[ChatProvider] Received 7TV event ${type} for ${chatroomId ?? 'broadcast'}`, | ||
| { | ||
| badgeCount: body?.badges?.length, | ||
| paintCount: body?.paints?.length, | ||
| entitlementUser: body?.object?.user?.username, | ||
| }, | ||
| ); | ||
|
|
||
| switch (type) { | ||
| case "connection_established": | ||
| break; | ||
| case "emote_set.update": | ||
| get().handleEmoteSetUpdate(chatroomId, body); | ||
| break; | ||
| case "cosmetic.create": | ||
| useCosmeticsStore?.getState()?.addCosmetics(body); | ||
| case "cosmetic.create": { | ||
| console.log( | ||
| `[ChatProvider] Applying cosmetic catalog update for ${chatroomId ?? 'all chatrooms'}`, | ||
| { | ||
| badges: body?.badges?.length, | ||
| paints: body?.paints?.length, | ||
| }, | ||
| ); | ||
| const addCosmetics = useCosmeticsStore?.getState()?.addCosmetics; | ||
| if (addCosmetics) { | ||
| if (window.__KT_TELEMETRY_UTILS__?.shouldLogDebug?.()) console.log(`[ChatProvider] Calling CosmeticsStore.addCosmetics with body:`, { | ||
| badges: body?.badges?.length, | ||
| paints: body?.paints?.length | ||
| }); | ||
| addCosmetics(body); | ||
| } else { | ||
| console.error(`[ChatProvider] CosmeticsStore.addCosmetics method not available!`); | ||
| } | ||
| break; | ||
| } | ||
| case "entitlement.create": { | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const username = body?.object?.user?.connections?.find((c) => c.platform === "KICK")?.username; | ||
| const transformedUsername = username?.replaceAll("-", "_").toLowerCase(); | ||
| useCosmeticsStore?.getState()?.addUserStyle(transformedUsername, body); | ||
| console.log( | ||
| `[ChatProvider] Processing entitlement for ${transformedUsername || 'unknown user'}`, | ||
| { | ||
| badgeId: body?.object?.user?.style?.badge_id, | ||
| paintId: body?.object?.user?.style?.paint_id, | ||
| chatroomId, | ||
| }, | ||
| ); | ||
| const addUserStyle = useCosmeticsStore?.getState()?.addUserStyle; | ||
| if (addUserStyle) { | ||
| console.log(`[ChatProvider] Calling CosmeticsStore.addUserStyle for ${transformedUsername}`); | ||
| addUserStyle(transformedUsername, body); | ||
| } else { | ||
| console.error(`[ChatProvider] CosmeticsStore.addUserStyle method not available!`); | ||
| } | ||
|
Comment on lines
+1964
to
+1977
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainUsername normalization may diverge from store lookups. You store under Prefer a shared normalizer used by both writer and reader (e.g., keep original username from KICK connection and only lowercase), or update getUserStyle to mirror the same normalization. 🏁 Script executed: #!/bin/bash
# Find all places replacing '-' with '_' for usernames to assess consistency
rg -nP "replaceAll\(\s*['\"]-['\"],\s*['\"]_['\"]\s*\).*username" -C2 --type=ts --type=tsx --type=js --type=jsxLength of output: 27 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "1) Searching for replaceAll occurrences (no type flags)..."
rg -n -C2 "replaceAll\(" || true
echo
echo "2) Searching for any replace( occurrences (showing context)..."
rg -n -C2 "replace\(" || true
echo
echo "3) Searching for transformedUsername occurrences..."
rg -n -C2 "transformedUsername" || true
echo
echo "4) Searching for getUserStyle occurrences..."
rg -n -C2 "getUserStyle" || true
echo
echo "5) Searching for addUserStyle occurrences..."
rg -n -C2 "addUserStyle" || true
echo
echo "6) Searching for CosmeticsStore occurrences..."
rg -n -C2 "CosmeticsStore" || true
echo
echo "7) Show ChatProvider.jsx snippet (lines 1900-1980) if file exists..."
if [ -f src/renderer/src/providers/ChatProvider.jsx ]; then
sed -n '1900,1980p' src/renderer/src/providers/ChatProvider.jsx || true
else
echo "src/renderer/src/providers/ChatProvider.jsx not found"
fiLength of output: 47048 Inconsistent username normalization — hyphenated usernames will miss stored cosmetics ChatProvider normalizes KICK usernames with username?.replaceAll("-", "_").toLowerCase() (src/renderer/src/providers/ChatProvider.jsx:1949) but CosmeticsProvider.addUserStyle/getUserStyle only call username.toLowerCase() (src/renderer/src/providers/CosmeticsProvider.jsx:32,75). Result: "foo-bar" vs "foo_bar" keys are inconsistent and lookups can fail. Fix: centralize normalization (e.g., utils/normalizeUsername that replaces '-'→'_' and lowercases) and use it in both addUserStyle and getUserStyle — or have getUserStyle mirror ChatProvider's replaceAll behavior before lookup. 🤖 Prompt for AI Agents |
||
| break; | ||
| } | ||
| case "entitlement.delete": { | ||
| const username = body?.object?.user?.connections?.find((c) => c.platform === "KICK")?.username; | ||
| const transformedUsername = username?.replaceAll("-", "_").toLowerCase(); | ||
| console.log( | ||
| `[ChatProvider] Processing entitlement deletion for ${transformedUsername || 'unknown user'}`, | ||
| { | ||
| refId: body?.object?.ref_id, | ||
| kind: body?.object?.kind, | ||
| chatroomId, | ||
| }, | ||
| ); | ||
| const removeUserStyle = useCosmeticsStore?.getState()?.removeUserStyle; | ||
| if (removeUserStyle) { | ||
| console.log(`[ChatProvider] Calling CosmeticsStore.removeUserStyle for ${transformedUsername}`); | ||
| removeUserStyle(transformedUsername, body); | ||
| } else { | ||
| console.error(`[ChatProvider] CosmeticsStore.removeUserStyle method not available!`); | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
|
|
@@ -2144,8 +2233,18 @@ const useChatStore = create((set, get) => ({ | |
| // Connect to chatroom | ||
| get().connectToChatroom(newChatroom); | ||
|
|
||
| // Connect to 7TV WebSocket | ||
| get().connectToStvWebSocket(newChatroom); | ||
| // Connect to 7TV WebSocket via connectionManager | ||
| if (connectionManager) { | ||
| console.log(`[ChatProvider] Adding new chatroom ${newChatroom.id} to connectionManager for 7TV subscriptions`); | ||
| try { | ||
| await connectionManager.addChatroom(newChatroom); | ||
| console.log(`[ChatProvider] Successfully added chatroom ${newChatroom.id} to connectionManager`); | ||
| } catch (error) { | ||
| console.error(`[ChatProvider] Error adding chatroom ${newChatroom.id} to connectionManager:`, error); | ||
| } | ||
| } else { | ||
| console.warn(`[ChatProvider] ConnectionManager not available for new chatroom ${newChatroom.id}`); | ||
| } | ||
|
|
||
| // Save to local storage | ||
| localStorage.setItem("chatrooms", JSON.stringify([...savedChatrooms, newChatroom])); | ||
|
|
@@ -3180,9 +3279,6 @@ const useChatStore = create((set, get) => ({ | |
| // Clear emote cache to ensure new emotes are loaded from updated store | ||
| clearChatroomEmoteCache(chatroomId); | ||
|
|
||
| // Refresh emote data to get the updated emote set | ||
| get().refresh7TVEmotes(chatroomId); | ||
|
|
||
| try { | ||
| const processingDuration = performance.now() - startTime; | ||
| // Record emote update metrics via IPC | ||
|
|
@@ -4031,7 +4127,9 @@ if (window.location.pathname === "/" || window.location.pathname.endsWith("index | |
| if (chatrooms?.length === 0) return; | ||
|
|
||
| chatrooms.forEach((chatroom) => { | ||
| console.log("[7tv Presence]: Sending presence check for chatroom:", chatroom.streamerData.user_id); | ||
| if (window.__KT_TELEMETRY_UTILS__?.shouldLogDebug?.()) { | ||
| console.log("[7tv Presence]: Sending presence check for chatroom:", chatroom.streamerData.user_id); | ||
| } | ||
| useChatStore.getState().sendPresenceUpdate(storeStvId, chatroom.streamerData.user_id); | ||
| }); | ||
| }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.