From a25ede128408bf8711e696f71f503ab43e6235f7 Mon Sep 17 00:00:00 2001 From: tapframe Date: Thu, 25 Sep 2025 22:17:39 +0530 Subject: [PATCH] trakt fix test --- .../home/ContinueWatchingSection.tsx | 39 +++++++++++++++++++ src/screens/StreamsScreen.tsx | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/components/home/ContinueWatchingSection.tsx b/src/components/home/ContinueWatchingSection.tsx index 90f4264..99fdd3a 100644 --- a/src/components/home/ContinueWatchingSection.tsx +++ b/src/components/home/ContinueWatchingSection.tsx @@ -227,10 +227,49 @@ const ContinueWatchingSection = React.forwardRef((props, re contentGroups[contentKey].episodes.push({ key, episodeId, progress, progressPercent }); } + // Fetch Trakt watched movies once and reuse + const traktMoviesSetPromise = (async () => { + try { + const traktService = TraktService.getInstance(); + const isAuthed = await traktService.isAuthenticated(); + if (!isAuthed) return new Set(); + if (typeof (traktService as any).getWatchedMovies === 'function') { + const watched = await (traktService as any).getWatchedMovies(); + if (Array.isArray(watched)) { + const ids = watched + .map((w: any) => w?.movie?.ids?.imdb) + .filter(Boolean) + .map((imdb: string) => (imdb.startsWith('tt') ? imdb : `tt${imdb}`)); + return new Set(ids); + } + } + return new Set(); + } catch { + return new Set(); + } + })(); + // Process each content group concurrently, merging results as they arrive const groupPromises = Object.values(contentGroups).map(async (group) => { try { if (!isSupportedId(group.id)) return; + // Skip movies that are already watched on Trakt + if (group.type === 'movie') { + const watchedSet = await traktMoviesSetPromise; + if (watchedSet.has(group.id)) { + // Optional: sync local store to watched to prevent reappearance + try { + await storageService.setWatchProgress(group.id, 'movie', { + currentTime: 1, + duration: 1, + lastUpdated: Date.now(), + traktSynced: true, + traktProgress: 100, + } as any); + } catch (_e) {} + return; + } + } const cachedData = await getCachedMetadata(group.type, group.id); if (!cachedData?.basicContent) return; const { metadata, basicContent } = cachedData; diff --git a/src/screens/StreamsScreen.tsx b/src/screens/StreamsScreen.tsx index 59a6811..0cf706c 100644 --- a/src/screens/StreamsScreen.tsx +++ b/src/screens/StreamsScreen.tsx @@ -224,7 +224,7 @@ const StreamCard = memo(({ stream, onPress, index, isLoading, statusMessage, the showAlert('Stream URL', stream.url); } } - }, [stream.url]); + }, [stream.url, showAlert]); const styles = React.useMemo(() => createStyles(theme.colors), [theme.colors]); const streamInfo = useMemo(() => {