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 2b271579f3
commit 58b9613f4b
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
6 changed files with 20 additions and 23 deletions

View file

@ -22,9 +22,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
### Improved
- Bangumi search now shows the score and summary of a search result ([@MajorTanya](https://github.com/MajorTanya)) ([#1396](https://github.com/mihonapp/mihon/pull/1396))
- Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya))
### Other
- Cleanup usage of `NetworkToLocalManga` ([@cuong-tran](https://github.com/cuong-tran)) ([#1435](https://github.com/mihonapp/mihon/pull/1435))
- Always update fresh data from source if manga isn't favorited ([@cuong-tran](https://github.com/cuong-tran)) ([#1435](https://github.com/mihonapp/mihon/pull/1435))
## [v0.17.0] - 2024-10-26
### Added

View file

@ -113,11 +113,9 @@ class BrowseSourceScreenModel(
getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters)
}.flow.map { pagingData ->
pagingData.map {
val networkManga = it.toDomainManga(sourceId)
networkToLocalManga.await(networkManga)
networkToLocalManga.await(it.toDomainManga(sourceId))
.let { localManga -> getManga.subscribe(localManga.url, localManga.source) }
.filterNotNull()
.map { manga -> manga.shouldUseNetworkMangaInfo(networkManga) }
.stateIn(ioCoroutineScope)
}
.filter { !hideInLibraryItems || !it.value.favorite }

View file

@ -166,9 +166,7 @@ abstract class SearchScreenModel(
}
val titles = page.mangas.map {
val networkManga = it.toDomainManga(source.id)
networkToLocalManga.await(networkManga)
.shouldUseNetworkMangaInfo(networkManga)
networkToLocalManga.await(it.toDomainManga(source.id))
}
if (isActive) {

View file

@ -15,7 +15,6 @@ import kotlinx.coroutines.flow.update
import tachiyomi.core.common.util.lang.launchIO
import tachiyomi.domain.chapter.interactor.GetChapterByUrlAndMangaId
import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.manga.interactor.GetMangaByUrlAndSourceId
import tachiyomi.domain.manga.interactor.NetworkToLocalManga
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.source.service.SourceManager
@ -27,7 +26,6 @@ class DeepLinkScreenModel(
private val sourceManager: SourceManager = Injekt.get(),
private val networkToLocalManga: NetworkToLocalManga = Injekt.get(),
private val getChapterByUrlAndMangaId: GetChapterByUrlAndMangaId = Injekt.get(),
private val getMangaByUrlAndSourceId: GetMangaByUrlAndSourceId = Injekt.get(),
private val syncChaptersWithSource: SyncChaptersWithSource = Injekt.get(),
) : StateScreenModel<DeepLinkScreenModel.State>(State.Loading) {
@ -74,9 +72,7 @@ class DeepLinkScreenModel(
}
private suspend fun getMangaFromSManga(sManga: SManga, sourceId: Long): Manga {
val networkManga = sManga.toDomainManga(sourceId)
return networkToLocalManga.await(networkManga)
.shouldUseNetworkMangaInfo(networkManga)
return networkToLocalManga.await(sManga.toDomainManga(sourceId))
}
sealed interface State {

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