trakt fix test

This commit is contained in:
tapframe 2025-09-25 22:17:39 +05:30
parent 3d9d0f297c
commit a25ede1284
2 changed files with 40 additions and 1 deletions

View file

@ -227,10 +227,49 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((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<string>();
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<string>(ids);
}
}
return new Set<string>();
} catch {
return new Set<string>();
}
})();
// 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;

View file

@ -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(() => {