Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 +72,7 @@ class DeepLinkScreenModel(
}

private suspend fun getMangaFromSManga(sManga: SManga, sourceId: Long): Manga {
return getMangaByUrlAndSourceId.await(sManga.url, sourceId)
?: networkToLocalManga.await(sManga.toDomainManga(sourceId))
return networkToLocalManga.await(sManga.toDomainManga(sourceId))
}

sealed interface State {
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/exh/GalleryAdder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,12 @@ class GalleryAdder(
} ?: return GalleryAddEvent.Fail.UnknownType(url, context)

// Use manga in DB if possible, otherwise, make a new manga
var manga = getManga.await(cleanedMangaUrl, source.id)
?: networkToLocalManga.await(
Manga.create().copy(
source = source.id,
url = cleanedMangaUrl,
),
)
var manga = networkToLocalManga.await(
Manga.create().copy(
source = source.id,
url = cleanedMangaUrl,
),
)

// Fetch and copy details
val newManga = retry(retry) { source.getMangaDetails(manga.toSManga()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tachiyomi.domain.manga.interactor

import exh.util.nullIfBlank
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.model.toMangaUpdate
import tachiyomi.domain.manga.repository.MangaRepository

class NetworkToLocalManga(
Expand All @@ -15,9 +17,15 @@ class NetworkToLocalManga(
manga.copy(id = id!!)
}
!localManga.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
localManga.copy(/* SY --> */ogTitle/* SY <-- */ = manga.title)
// if the manga isn't a favorite, update new info from source to db
mangaRepository.update(
manga.toMangaUpdate()
.copy(
id = localManga.id,
thumbnailUrl = manga.ogThumbnailUrl?.nullIfBlank(),
),
)
manga.copy(id = localManga.id)
}
else -> {
localManga
Expand Down
Loading