Skip to content

Commit

Permalink
Always update fresh data from source if manga isn't favorited
Browse files Browse the repository at this point in the history
  • Loading branch information
cuong-tran committed Nov 2, 2024
1 parent 2b27157 commit 58b9613
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
}
Expand All @@ -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() },
),
)
}
}
9 changes: 0 additions & 9 deletions domain/src/main/java/tachiyomi/domain/manga/model/Manga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58b9613

Please sign in to comment.