ref: add collections support to local account data cleaner

This commit is contained in:
tapframe 2026-05-06 23:46:38 +05:30
parent b293157fee
commit 5a0b623773
3 changed files with 10 additions and 10 deletions

View file

@ -23,6 +23,7 @@ internal actual object PlatformLocalAccountDataCleaner {
"nuvio_episode_release_notifications", "nuvio_episode_release_notifications",
"nuvio_episode_release_notifications_platform", "nuvio_episode_release_notifications_platform",
"nuvio_watch_progress", "nuvio_watch_progress",
"nuvio_collections",
"nuvio_plugins", "nuvio_plugins",
) )

View file

@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonNull
import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put import kotlinx.serialization.json.put
@ -56,16 +57,13 @@ object CollectionSyncService {
return return
} }
val remoteJson = blob.collectionsJson.toString() val remoteCollectionsJson = if (blob.collectionsJson == JsonNull) {
val localJson = CollectionRepository.exportToJson() JsonArray(emptyList())
} else {
if (remoteJson == "[]" || remoteJson == "null") { blob.collectionsJson
val currentCollections = CollectionRepository.collections.value
if (currentCollections.isNotEmpty()) {
log.i { "pullFromServer — remote empty, preserving local ${currentCollections.size} collections" }
return
}
} }
val remoteJson = remoteCollectionsJson.toString()
val localJson = CollectionRepository.exportToJson()
if (remoteJson == localJson) { if (remoteJson == localJson) {
log.d { "pullFromServer — remote matches local, no update needed" } log.d { "pullFromServer — remote matches local, no update needed" }
@ -78,7 +76,7 @@ object CollectionSyncService {
if (remoteCollections != null) { if (remoteCollections != null) {
isSyncingFromRemote = true isSyncingFromRemote = true
CollectionRepository.applyFromRemote(remoteCollections, blob.collectionsJson) CollectionRepository.applyFromRemote(remoteCollections, remoteCollectionsJson)
isSyncingFromRemote = false isSyncingFromRemote = false
log.i { "pullFromServer — applied ${remoteCollections.size} collections from remote" } log.i { "pullFromServer — applied ${remoteCollections.size} collections from remote" }
} else { } else {

View file

@ -46,6 +46,7 @@ internal actual object PlatformLocalAccountDataCleaner {
"trakt_auth_payload", "trakt_auth_payload",
"trakt_library_payload", "trakt_library_payload",
"trakt_settings_payload", "trakt_settings_payload",
"collections_payload",
) )
actual fun wipe() { actual fun wipe() {