From a079649563e8d1e02cdc5f68afa774e9ab105c38 Mon Sep 17 00:00:00 2001 From: chrisk325 Date: Sat, 3 Jan 2026 01:23:40 +0530 Subject: [PATCH] fix trakt syncing watched shows/movies back to trakt's recent history --- src/hooks/useTraktIntegration.ts | 75 +++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/src/hooks/useTraktIntegration.ts b/src/hooks/useTraktIntegration.ts index 2a992b3..a0fdc6d 100644 --- a/src/hooks/useTraktIntegration.ts +++ b/src/hooks/useTraktIntegration.ts @@ -559,15 +559,23 @@ export function useTraktIntegration() { return undefined; })(); - updatePromises.push( - storageService.mergeWithTraktProgress( - id, - type, - item.progress, - item.paused_at, - episodeId, - exactTime - ) + // Merge with local progress + await storageService.mergeWithTraktProgress( + id, + type, + item.progress, + item.paused_at, + episodeId, + exactTime + ); + + // FIX: Mark as already synced so it won't be re-uploaded to Trakt + await storageService.updateTraktSyncStatus( + id, + type, + true, // synced = true + item.progress, + episodeId ); } catch (error) { logger.error('[useTraktIntegration] Error preparing Trakt progress update:', error); @@ -581,19 +589,27 @@ export function useTraktIntegration() { const id = movie.movie.ids.imdb; const watchedAt = movie.last_watched_at; - updatePromises.push( - storageService.mergeWithTraktProgress( - id, - 'movie', - 100, // 100% progress for watched items - watchedAt - ) + await storageService.mergeWithTraktProgress( + id, + 'movie', + 100, + watchedAt + ); + + // FIX: Mark as already synced + await storageService.updateTraktSyncStatus( + id, + 'movie', + true, + 100 ); } } catch (error) { - logger.error('[useTraktIntegration] Error preparing watched movie update:', error); + logger.error('[useTraktIntegration] Error preparing watched movie update:', error); } } + + // Process watched shows (100% completed episodes) for (const show of watchedShows) { try { if (show.show?.ids?.imdb && show.seasons) { @@ -602,14 +618,22 @@ export function useTraktIntegration() { for (const season of show.seasons) { for (const episode of season.episodes) { const episodeId = `${showImdbId}:${season.number}:${episode.number}`; - updatePromises.push( - storageService.mergeWithTraktProgress( - showImdbId, - 'series', - 100, - episode.last_watched_at, - episodeId - ) + + await storageService.mergeWithTraktProgress( + showImdbId, + 'series', + 100, + episode.last_watched_at, + episodeId + ); + + // FIX: Mark as already synced + await storageService.updateTraktSyncStatus( + showImdbId, + 'series', + true, + 100, + episodeId ); } } @@ -618,6 +642,7 @@ export function useTraktIntegration() { logger.error('[useTraktIntegration] Error preparing watched show update:', error); } } + // Execute all updates in parallel await Promise.all(updatePromises);