fix: trakt duplicating same timestamp history

This commit is contained in:
tapframe 2026-05-16 19:43:15 +05:30
parent 70d3eee9d2
commit ac48ab11b2
4 changed files with 40 additions and 3 deletions

View file

@ -382,8 +382,10 @@ object WatchProgressRepository {
ContinueWatchingPreferencesRepository.removeDismissedNextUpKeysForContent(entry.parentMetaId)
}
val useTraktProgress = shouldUseTraktProgress()
entriesByVideoId[session.videoId] = entry
if (shouldUseTraktProgress()) {
if (useTraktProgress) {
TraktProgressRepository.applyOptimisticProgress(entry)
}
publish()
@ -392,7 +394,9 @@ object WatchProgressRepository {
resolveRemoteMetadata()
}
pushScrobbleToServer(entry)
WatchingActions.onProgressEntryUpdated(entry)
if (shouldCascadeCompletedProgressToWatchedHistory(entry, useTraktProgress)) {
WatchingActions.onProgressEntryUpdated(entry)
}
}
private fun pushScrobbleToServer(entry: WatchProgressEntry) {

View file

@ -99,6 +99,11 @@ internal fun WatchProgressEntry.shouldUseAsCompletedSeedForContinueWatching(): B
return explicitPercent >= WatchProgressTraktPlaybackNextUpSeedPercentThreshold
}
internal fun shouldCascadeCompletedProgressToWatchedHistory(
entry: WatchProgressEntry,
isUsingTraktProgress: Boolean,
): Boolean = !isUsingTraktProgress && entry.normalizedCompletion().isCompleted
internal fun String?.isSeriesTypeForContinueWatching(): Boolean =
equals("series", ignoreCase = true) || equals("tv", ignoreCase = true)

View file

@ -173,6 +173,34 @@ class WatchProgressRulesTest {
assertFalse(history.shouldTreatAsInProgressForContinueWatching())
}
@Test
fun `completed progress does not cascade to watched history while Trakt progress is active`() {
val completed = entry(
videoId = "movie-complete",
isCompleted = true,
)
val inProgress = completed.copy(isCompleted = false)
assertFalse(
shouldCascadeCompletedProgressToWatchedHistory(
entry = completed,
isUsingTraktProgress = true,
),
)
assertTrue(
shouldCascadeCompletedProgressToWatchedHistory(
entry = completed,
isUsingTraktProgress = false,
),
)
assertFalse(
shouldCascadeCompletedProgressToWatchedHistory(
entry = inProgress,
isUsingTraktProgress = false,
),
)
}
@Test
fun `codec normalizes completed entries inferred from percent`() {
val payload = WatchProgressCodec.encodeEntries(

View file

@ -1,3 +1,3 @@
CURRENT_PROJECT_VERSION=62
MARKETING_VERSION=0.1.20
MARKETING_VERSION=0.1.0