Subscribe to changes to manga in BrowseSourceScreen

Fixes #9235
This commit is contained in:
arkon 2023-03-26 12:06:12 -04:00
parent 35d381144d
commit e932983494

View file

@ -54,6 +54,7 @@ import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
import tachiyomi.domain.chapter.interactor.SetMangaDefaultChapterFlags
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.interactor.GetDuplicateLibraryManga
import tachiyomi.domain.manga.interactor.GetManga
import tachiyomi.domain.manga.interactor.NetworkToLocalManga
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.model.toMangaUpdate
@ -78,6 +79,7 @@ class BrowseSourceScreenModel(
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
private val setMangaCategories: SetMangaCategories = Injekt.get(),
private val setMangaDefaultChapterFlags: SetMangaDefaultChapterFlags = Injekt.get(),
private val getManga: GetManga = Injekt.get(),
private val networkToLocalManga: NetworkToLocalManga = Injekt.get(),
private val updateManga: UpdateManga = Injekt.get(),
private val insertTrack: InsertTrack = Injekt.get(),
@ -121,19 +123,20 @@ class BrowseSourceScreenModel(
) {
getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters)
}.flow.map { pagingData ->
pagingData
.map {
flow {
val localManga = withIOContext { networkToLocalManga.await(it.toDomainManga(sourceId)) }
emit(localManga)
}
pagingData.map {
withIOContext {
networkToLocalManga.await(it.toDomainManga(sourceId))
.let { localManga ->
getManga.subscribe(localManga.url, localManga.source)
}
.filterNotNull()
.filter {
!sourcePreferences.hideInLibraryItems().get() || !it.favorite
.filter { localManga ->
!sourcePreferences.hideInLibraryItems().get() || !localManga.favorite
}
.onEach(::initializeManga)
.stateIn(coroutineScope)
}
}
}
.cachedIn(coroutineScope)
}