diff --git a/js/feedEngine/watchHistoryFeed.js b/js/feedEngine/watchHistoryFeed.js index 4f5dc2bb..c1d42452 100644 --- a/js/feedEngine/watchHistoryFeed.js +++ b/js/feedEngine/watchHistoryFeed.js @@ -9,6 +9,7 @@ import { isWatchHistoryDebugEnabled, logWatchHistoryDebug, } from "../watchHistoryDebug.js"; +import { devLogger } from "../utils/logger.js"; import { createBlacklistFilterStage, createWatchHistorySuppressionStage, @@ -18,11 +19,11 @@ import { isPlainObject } from "./utils.js"; const WATCH_HISTORY_FEED_LOG_NAMESPACE = "watchHistoryFeed"; function debugInfo(message, details) { - logWatchHistoryDebug(WATCH_HISTORY_FEED_LOG_NAMESPACE, "info", message, details); + devLogger.info(`[${WATCH_HISTORY_FEED_LOG_NAMESPACE}] ${message}`, details || ""); } function debugWarn(message, details) { - logWatchHistoryDebug(WATCH_HISTORY_FEED_LOG_NAMESPACE, "warn", message, details); + devLogger.warn(`[${WATCH_HISTORY_FEED_LOG_NAMESPACE}] ${message}`, details || ""); } function normalizeActorCandidate(...values) { @@ -249,11 +250,13 @@ function checkLocalCacheForVideo(pointer) { function createWatchHistoryHydrationStage() { return async function watchHistoryHydrationStage(items = [], context = {}) { + debugInfo(`Starting hydration stage for ${items.length} items.`); const missing = []; const missingAddresses = []; const idMap = new Map(); const itemsToHydrate = items.filter(item => !item.video && item.pointer); + debugInfo(`Items needing hydration: ${itemsToHydrate.length}`); let addressScanNeeded = false; // First pass: try to resolve from cache for IDs, and collect addresses @@ -312,12 +315,15 @@ function createWatchHistoryHydrationStage() { } if (!missing.length && !missingAddresses.length) { + debugInfo("No missing items to fetch from relays."); return items; } const uniqueIds = Array.from(new Set(missing)); const uniqueAddresses = Array.from(new Set(missingAddresses)); + debugInfo(`Fetching from relays. Missing IDs: ${uniqueIds.length}, Missing Addresses: ${uniqueAddresses.length}`); + const readRelays = Array.isArray(nostrClient?.readRelays) && nostrClient.readRelays.length ? nostrClient.readRelays @@ -330,7 +336,10 @@ function createWatchHistoryHydrationStage() { const relays = readRelays || fallbackRelays; + debugInfo("Selected relays for hydration:", relays); + if (!relays || !nostrClient?.pool) { + debugWarn("Aborting hydration: No relays or pool available."); return items; } @@ -361,9 +370,13 @@ function createWatchHistoryHydrationStage() { } } + debugInfo("Generated filters:", filters); + try { const events = await nostrClient.pool.list(relays, filters); + debugInfo(`Hydration fetch returned ${events.length} events.`); + let matchCount = 0; for (const event of events) { if (!event) { continue; @@ -380,6 +393,7 @@ function createWatchHistoryHydrationStage() { if (target.metadata) { target.metadata.video = video; } + matchCount++; } } } @@ -395,6 +409,7 @@ function createWatchHistoryHydrationStage() { if (target.metadata) { target.metadata.video = video; } + matchCount++; } } } @@ -403,6 +418,7 @@ function createWatchHistoryHydrationStage() { debugWarn(`[watchHistoryFeed] Failed to convert event ${event.id}:`, err); } } + debugInfo(`Hydrated ${matchCount} items from fetched events.`); } catch (error) { debugWarn("[watchHistoryFeed] Hydration fetch failed:", error); }