SmartUpdateRules.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/library/SmartUpdateRules.kt
1package eu.friedcutlet.yokan.services.library23import eu.friedcutlet.yokan.database.DbChapter4import eu.friedcutlet.yokan.database.DbManga5import eu.friedcutlet.yokan.database.DbSmartUpdateRules6import eu.friedcutlet.yokan.database.DbStatus7import eu.friedcutlet.yokan.domain.effectiveChapterUpdateDays89/** Pure admission rule shared by manual library refreshes and all scheduler entry points. */10internal fun DbSmartUpdateRules.permits(manga: DbManga, chapters: List<DbChapter>, now: Long): Boolean {11 if (skipCompleted && manga.status == DbStatus.Completed) return false12 if (onlyCaughtUp && chapters.any { !it.isRead }) return false13 if (onlyStarted && chapters.isNotEmpty() && chapters.none { chapter ->14 chapter.isRead || (chapter.lastPageRead.toDoubleOrNull()?.let { it.isFinite() && it > 0 } == true)15 }) return false16 if (!respectExpectedReleasePeriod) return true17 val days = effectiveChapterUpdateDays(manga.smartUpdateDays,18 if (manga.smartUpdateDays == null) chapters.map { it.dateUpload } else emptyList(), now)19 if (days <= 0) return true20 return now - (manga.lastUpdate ?: 0L) >= days.toLong() * 86_400_000L21}22