Always update fresh data from source if manga isn't favorited

This commit is contained in:
Cuong-Tran
2024-11-03 01:55:16 +07:00
parent 71d0d2d723
commit 47140c923f
6 changed files with 20 additions and 23 deletions

View File

@@ -1,6 +1,7 @@
package tachiyomi.domain.manga.interactor
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.model.toMangaUpdate
import tachiyomi.domain.manga.repository.MangaRepository
class NetworkToLocalManga(
@@ -14,6 +15,11 @@ class NetworkToLocalManga(
val id = insertManga(manga)
manga.copy(id = id!!)
}
!localManga.favorite -> {
// if the manga isn't a favorite, update new info from source to db
manga.updateManga(localManga.id)
manga.copy(id = localManga.id)
}
else -> {
localManga
}
@@ -27,4 +33,14 @@ class NetworkToLocalManga(
private suspend fun insertManga(manga: Manga): Long? {
return mangaRepository.insert(manga)
}
private suspend fun Manga.updateManga(id: Long) {
mangaRepository.update(
toMangaUpdate()
.copy(
id = id,
thumbnailUrl = thumbnailUrl?.takeIf { it.isNotBlank() },
),
)
}
}

View File

@@ -72,15 +72,6 @@ data class Manga(
return chapterFlags and CHAPTER_SORT_DIR_MASK == CHAPTER_SORT_DESC
}
fun shouldUseNetworkMangaInfo(networkManga: Manga): Manga =
if (!favorite) {
// if the manga isn't a favorite, set its display title from source
// if it later becomes a favorite, updated title will go to db
copy(title = networkManga.title)
} else {
this
}
companion object {
// Generic filter that does not filter anything
const val SHOW_ALL = 0x00000000L