fix: bound time remaining to mark a video as watched (#7173)

This commit is contained in:
Clar Fon 2025-03-08 05:38:46 -05:00 committed by GitHub
parent 71288ec3e0
commit f6aa7efeed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,6 +15,12 @@ import kotlinx.coroutines.withContext
object DatabaseHelper { object DatabaseHelper {
private const val MAX_SEARCH_HISTORY_SIZE = 20 private const val MAX_SEARCH_HISTORY_SIZE = 20
// can only mark as watched if less than 60s remaining
private const val ABSOLUTE_WATCHED_THRESHOLD = 60.0f
// can only mark as watched if at least 75% watched
private const val RELATIVE_WATCHED_THRESHOLD = 0.75f
suspend fun addToWatchHistory(watchHistoryItem: WatchHistoryItem) = suspend fun addToWatchHistory(watchHistoryItem: WatchHistoryItem) =
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
Database.watchHistoryDao().insert(watchHistoryItem) Database.watchHistoryDao().insert(watchHistoryItem)
@ -79,8 +85,8 @@ object DatabaseHelper {
if (durationSeconds == null) return false if (durationSeconds == null) return false
val progress = positionMillis / 1000 val progress = positionMillis / 1000
// show video only in feed when watched less than 90%
return progress > 0.9f * durationSeconds return durationSeconds - progress <= ABSOLUTE_WATCHED_THRESHOLD && progress >= RELATIVE_WATCHED_THRESHOLD * durationSeconds
} }
suspend fun filterUnwatched(streams: List<StreamItem>): List<StreamItem> { suspend fun filterUnwatched(streams: List<StreamItem>): List<StreamItem> {