Merge branch 'cmp-rewrite' into torinit

This commit is contained in:
tapframe 2026-05-30 19:32:46 +05:30
commit 16a068cd61
5 changed files with 21 additions and 12 deletions

View file

@ -21,7 +21,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
private const val FOREGROUND_PULL_DELAY_MS = 2500L
private const val FOREGROUND_PULL_MIN_INTERVAL_MS = 60_000L
private const val FOREGROUND_PULL_MIN_INTERVAL_MS = 30 * 60_000L
object SyncManager {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)

View file

@ -2168,6 +2168,7 @@ fun PlayerScreen(
WatchProgressRepository.upsertPlaybackProgress(
session = playbackSession,
snapshot = playbackSnapshot,
syncRemote = false,
)
}

View file

@ -147,13 +147,14 @@ object WatchedRepository {
markWatched(items = items, traktHistorySync = WatchedTraktHistorySync.Mirror)
}
internal fun markWatchedFromPlaybackCompletion(item: WatchedItem) {
markWatched(items = listOf(item), traktHistorySync = WatchedTraktHistorySync.Skip)
internal fun markWatchedFromPlaybackCompletion(item: WatchedItem, syncRemote: Boolean = true) {
markWatched(items = listOf(item), traktHistorySync = WatchedTraktHistorySync.Skip, syncRemote = syncRemote)
}
private fun markWatched(
items: Collection<WatchedItem>,
traktHistorySync: WatchedTraktHistorySync,
syncRemote: Boolean = true,
) {
ensureLoaded()
if (items.isEmpty()) return
@ -167,7 +168,9 @@ object WatchedRepository {
}
publish()
persist()
pushMarksToServer(timestampedItems, traktHistorySync)
if (syncRemote) {
pushMarksToServer(timestampedItems, traktHistorySync)
}
}
fun unmarkWatched(item: WatchedItem) {

View file

@ -117,7 +117,7 @@ object WatchingActions {
)
}
fun onProgressEntryUpdated(entry: WatchProgressEntry) {
fun onProgressEntryUpdated(entry: WatchProgressEntry, syncRemote: Boolean = true) {
if (!entry.isCompleted) return
val watchedItem = WatchedItem(
@ -129,9 +129,9 @@ object WatchingActions {
episode = entry.episodeNumber,
markedAtEpochMs = entry.lastUpdatedEpochMs,
)
WatchedRepository.markWatchedFromPlaybackCompletion(watchedItem)
WatchedRepository.markWatchedFromPlaybackCompletion(watchedItem, syncRemote = syncRemote)
if (!entry.isEpisode) return
if (!syncRemote || !entry.isEpisode) return
actionScope.launch {
val meta = runCatching {
MetaDetailsRepository.fetch(

View file

@ -39,7 +39,7 @@ import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import kotlinx.coroutines.withTimeoutOrNull
private const val NUVIO_SYNC_PERIODIC_INTERVAL_MS = 5L * 60L * 1000L
private const val NUVIO_SYNC_PERIODIC_INTERVAL_MS = 30L * 60L * 1000L
private const val WATCH_PROGRESS_METADATA_RESOLUTION_CONCURRENCY = 4
private const val WATCH_PROGRESS_METADATA_RESOLUTION_LIMIT = 64
@ -419,17 +419,19 @@ object WatchProgressRepository {
fun upsertPlaybackProgress(
session: WatchProgressPlaybackSession,
snapshot: PlayerPlaybackSnapshot,
syncRemote: Boolean = true,
) {
ensureLoaded()
upsert(session = session, snapshot = snapshot, persist = true)
upsert(session = session, snapshot = snapshot, persist = true, syncRemote = syncRemote)
}
fun flushPlaybackProgress(
session: WatchProgressPlaybackSession,
snapshot: PlayerPlaybackSnapshot,
syncRemote: Boolean = true,
) {
ensureLoaded()
upsert(session = session, snapshot = snapshot, persist = true)
upsert(session = session, snapshot = snapshot, persist = true, syncRemote = syncRemote)
}
fun clearProgress(videoId: String) {
@ -561,6 +563,7 @@ object WatchProgressRepository {
session: WatchProgressPlaybackSession,
snapshot: PlayerPlaybackSnapshot,
persist: Boolean,
syncRemote: Boolean,
) {
val positionMs = snapshot.positionMs.coerceAtLeast(0L)
val durationMs = snapshot.durationMs.coerceAtLeast(0L)
@ -613,9 +616,11 @@ object WatchProgressRepository {
if (entry.poster.isNullOrBlank() || entry.background.isNullOrBlank()) {
resolveRemoteMetadata()
}
pushScrobbleToServer(entry)
if (syncRemote) {
pushScrobbleToServer(entry)
}
if (shouldCascadeCompletedProgressToWatchedHistory(entry, useTraktProgress)) {
WatchingActions.onProgressEntryUpdated(entry)
WatchingActions.onProgressEntryUpdated(entry, syncRemote = syncRemote)
}
}