fix: local cw removal not taking effect on cloud

This commit is contained in:
tapframe 2026-03-15 09:39:59 +05:30
parent 4ce9d4de08
commit 69df218b40
2 changed files with 14 additions and 10 deletions

View file

@ -50,7 +50,6 @@ class WatchProgressSyncService @Inject constructor(
suspend fun deleteFromRemote(keys: Collection<String>): Result<Unit> = withContext(Dispatchers.IO) {
try {
if (!shouldUseSupabaseWatchProgressSync()) {
Log.d(TAG, "Using Trakt watch progress, skipping watch progress delete")
return@withContext Result.success(Unit)
}

View file

@ -425,10 +425,11 @@ class WatchProgressRepositoryImpl @Inject constructor(
override suspend fun removeProgress(contentId: String, season: Int?, episode: Int?) {
val useTraktProgress = shouldUseTraktProgress()
val hasEffectiveTraktConnection = hasEffectiveTraktConnection()
Log.d(
TAG,
"removeProgress called contentId=$contentId season=$season episode=$episode useTraktProgress=$useTraktProgress hasEffectiveTraktConnection=$hasEffectiveTraktConnection"
)
val remoteDeleteKeys = if (!useTraktProgress) {
resolveRemoteDeleteKeys(contentId, season, episode)
} else {
emptyList()
}
if (hasEffectiveTraktConnection) {
traktProgressService.applyOptimisticRemoval(contentId, season, episode)
traktProgressService.removeProgress(contentId, season, episode)
@ -437,7 +438,6 @@ class WatchProgressRepositoryImpl @Inject constructor(
if (useTraktProgress) {
return
}
val remoteDeleteKeys = resolveRemoteDeleteKeys(contentId, season, episode)
if (authManager.isAuthenticated && remoteDeleteKeys.isNotEmpty()) {
watchProgressSyncService.deleteFromRemote(remoteDeleteKeys)
.onFailure { error ->
@ -449,6 +449,11 @@ class WatchProgressRepositoryImpl @Inject constructor(
override suspend fun removeFromHistory(contentId: String, videoId: String?, season: Int?, episode: Int?) {
val useTraktProgress = shouldUseTraktProgress()
val remoteDeleteKeys = if (!useTraktProgress) {
resolveRemoteDeleteKeys(contentId, season, episode)
} else {
emptyList()
}
if (hasEffectiveTraktConnection()) {
traktProgressService.removeFromHistory(contentId, videoId, season, episode)
}
@ -457,7 +462,6 @@ class WatchProgressRepositoryImpl @Inject constructor(
if (useTraktProgress) {
return
}
val remoteDeleteKeys = resolveRemoteDeleteKeys(contentId, season, episode)
if (authManager.isAuthenticated && remoteDeleteKeys.isNotEmpty()) {
watchProgressSyncService.deleteFromRemote(remoteDeleteKeys)
.onFailure { error ->
@ -564,21 +568,22 @@ class WatchProgressRepositoryImpl @Inject constructor(
season: Int?,
episode: Int?
): List<String> {
val rawEntries = watchProgressPreferences.getAllRawEntries()
val keys = if (season != null && episode != null) {
listOf("${contentId}_s${season}e${episode}", contentId)
} else {
val matchingLocalKeys = watchProgressPreferences
.getAllRawEntries()
val matchingLocalKeys = rawEntries
.keys
.filter { key ->
key == contentId || key.startsWith("${contentId}_")
}
matchingLocalKeys + contentId
}
return keys
val resolvedKeys = keys
.map { it.trim() }
.filter { it.isNotEmpty() }
.distinct()
return resolvedKeys
}
}