Set source properly when creating manga entries
Fixes #8333 (cherry picked from commit cac80daa714a8dc3906954b514cd6e3baa140aa1) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt
This commit is contained in:
parent
402a883f7f
commit
2bbb374e40
@ -7,11 +7,11 @@ class NetworkToLocalManga(
|
||||
private val mangaRepository: MangaRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(manga: Manga, sourceId: Long): Manga {
|
||||
val localManga = getManga(manga.url, sourceId)
|
||||
suspend fun await(manga: Manga): Manga {
|
||||
val localManga = getManga(manga.url, manga.source)
|
||||
return when {
|
||||
localManga == null -> {
|
||||
val id = insertManga(manga, sourceId)
|
||||
val id = insertManga(manga)
|
||||
manga.copy(id = id!!)
|
||||
}
|
||||
!localManga.favorite -> {
|
||||
@ -29,7 +29,7 @@ class NetworkToLocalManga(
|
||||
return mangaRepository.getMangaByUrlAndSourceId(url, sourceId)
|
||||
}
|
||||
|
||||
private suspend fun insertManga(manga: Manga, sourceId: Long): Long? {
|
||||
return mangaRepository.insert(manga.copy(source = sourceId))
|
||||
private suspend fun insertManga(manga: Manga): Long? {
|
||||
return mangaRepository.insert(manga)
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ fun Manga.toMangaUpdate(): MangaUpdate {
|
||||
)
|
||||
}
|
||||
|
||||
fun SManga.toDomainManga(): Manga {
|
||||
fun SManga.toDomainManga(sourceId: Long): Manga {
|
||||
return Manga.create().copy(
|
||||
url = url,
|
||||
// SY -->
|
||||
@ -309,6 +309,7 @@ fun SManga.toDomainManga(): Manga {
|
||||
thumbnailUrl = thumbnail_url,
|
||||
updateStrategy = update_strategy,
|
||||
initialized = initialized,
|
||||
source = sourceId,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -734,7 +734,6 @@ class LibraryUpdateService(
|
||||
favorite = true,
|
||||
dateAdded = System.currentTimeMillis(),
|
||||
),
|
||||
mangaDex.id,
|
||||
)
|
||||
} else if (!dbManga.favorite) {
|
||||
updateManga.awaitUpdateFavorite(dbManga.id, true)
|
||||
|
@ -55,13 +55,7 @@ class SourceManager(
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||
|
||||
private var sourcesMap = ConcurrentHashMap<Long, Source>()
|
||||
set(value) {
|
||||
field = value
|
||||
sourcesMapFlow.value = field
|
||||
}
|
||||
|
||||
private val sourcesMapFlow = MutableStateFlow(sourcesMap)
|
||||
private val sourcesMapFlow = MutableStateFlow(ConcurrentHashMap<Long, Source>())
|
||||
|
||||
private val stubSourcesMap = ConcurrentHashMap<Long, StubSource>()
|
||||
|
||||
@ -96,7 +90,7 @@ class SourceManager(
|
||||
registerStubSource(it.toSourceData())
|
||||
}
|
||||
}
|
||||
sourcesMap = mutableMap
|
||||
sourcesMapFlow.value = mutableMap
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,18 +148,18 @@ class SourceManager(
|
||||
}
|
||||
|
||||
fun get(sourceKey: Long): Source? {
|
||||
return sourcesMap[sourceKey]
|
||||
return sourcesMapFlow.value[sourceKey]
|
||||
}
|
||||
|
||||
fun getOrStub(sourceKey: Long): Source {
|
||||
return sourcesMap[sourceKey] ?: stubSourcesMap.getOrPut(sourceKey) {
|
||||
return sourcesMapFlow.value[sourceKey] ?: stubSourcesMap.getOrPut(sourceKey) {
|
||||
runBlocking { createStubSource(sourceKey) }
|
||||
}
|
||||
}
|
||||
|
||||
fun getOnlineSources() = sourcesMap.values.filterIsInstance<HttpSource>()
|
||||
fun getOnlineSources() = sourcesMapFlow.value.values.filterIsInstance<HttpSource>()
|
||||
|
||||
fun getCatalogueSources() = sourcesMap.values.filterIsInstance<CatalogueSource>()
|
||||
fun getCatalogueSources() = sourcesMapFlow.value.values.filterIsInstance<CatalogueSource>()
|
||||
|
||||
fun getStubSources(): List<StubSource> {
|
||||
val onlineSourceIds = getOnlineSources().map { it.id }
|
||||
@ -173,15 +167,15 @@ class SourceManager(
|
||||
}
|
||||
|
||||
// SY -->
|
||||
fun getVisibleOnlineSources() = sourcesMap.values.filterIsInstance<HttpSource>().filter {
|
||||
fun getVisibleOnlineSources() = sourcesMapFlow.value.values.filterIsInstance<HttpSource>().filter {
|
||||
it.id !in BlacklistedSources.HIDDEN_SOURCES
|
||||
}
|
||||
|
||||
fun getVisibleCatalogueSources() = sourcesMap.values.filterIsInstance<CatalogueSource>().filter {
|
||||
fun getVisibleCatalogueSources() = sourcesMapFlow.value.values.filterIsInstance<CatalogueSource>().filter {
|
||||
it.id !in BlacklistedSources.HIDDEN_SOURCES
|
||||
}
|
||||
|
||||
fun getDelegatedCatalogueSources() = sourcesMap.values.filterIsInstance<EnhancedHttpSource>().mapNotNull { enhancedHttpSource ->
|
||||
fun getDelegatedCatalogueSources() = sourcesMapFlow.value.values.filterIsInstance<EnhancedHttpSource>().mapNotNull { enhancedHttpSource ->
|
||||
enhancedHttpSource.enhancedSource as? DelegatedHttpSource
|
||||
}
|
||||
// SY <--
|
||||
|
@ -153,7 +153,6 @@ class MergedSource : HttpSource() {
|
||||
source = mangaSourceId,
|
||||
url = mangaUrl,
|
||||
),
|
||||
mangaSourceId,
|
||||
)
|
||||
updateManga.awaitUpdateFromSource(newManga, source.getMangaDetails(newManga.toSManga()), false)
|
||||
manga = getManga.await(newManga.id)!!
|
||||
|
@ -201,7 +201,7 @@ open class FeedPresenter(
|
||||
.subscribeOn(Schedulers.io())
|
||||
.onErrorReturn { MangasPage(emptyList(), false) } // Ignore timeouts or other exceptions
|
||||
.map { it.mangas } // Get manga from search result.
|
||||
.map { list -> runBlocking { list.map { networkToLocalManga.await(it.toDomainManga(), itemUI.source.id) } } } // Convert to local manga.
|
||||
.map { list -> runBlocking { list.map { networkToLocalManga.await(it.toDomainManga(itemUI.source.id)) } } } // Convert to local manga.
|
||||
.map { list -> itemUI.copy(results = list) }
|
||||
} else {
|
||||
Observable.just(itemUI.copy(results = emptyList()))
|
||||
|
@ -179,10 +179,7 @@ class MigrationListPresenter(
|
||||
}
|
||||
|
||||
if (searchResult != null && !(searchResult.url == mangaObj.url && source.id == mangaObj.source)) {
|
||||
val localManga = networkToLocalManga.await(
|
||||
searchResult,
|
||||
source.id,
|
||||
)
|
||||
val localManga = networkToLocalManga.await(searchResult)
|
||||
|
||||
val chapters = if (source is EHentai) {
|
||||
source.getChapterList(localManga.toSManga(), throttleManager::throttle)
|
||||
@ -219,7 +216,7 @@ class MigrationListPresenter(
|
||||
}
|
||||
|
||||
if (searchResult != null) {
|
||||
val localManga = networkToLocalManga.await(searchResult, source.id)
|
||||
val localManga = networkToLocalManga.await(searchResult)
|
||||
val chapters = try {
|
||||
if (source is EHentai) {
|
||||
source.getChapterList(localManga.toSManga(), throttleManager::throttle)
|
||||
@ -384,7 +381,7 @@ class MigrationListPresenter(
|
||||
migratingManga.searchResult.value = SearchResult.Searching
|
||||
presenterScope.launchIO {
|
||||
val result = migratingManga.migrationScope.async {
|
||||
val localManga = networkToLocalManga.await(manga, source.id)
|
||||
val localManga = networkToLocalManga.await(manga)
|
||||
try {
|
||||
val chapters = source.getChapterList(localManga.toSManga())
|
||||
syncChaptersWithSource.await(chapters, localManga, source)
|
||||
|
@ -171,7 +171,7 @@ open class BrowseSourcePresenter(
|
||||
it.map { (sManga, metadata) ->
|
||||
// SY -->
|
||||
withIOContext {
|
||||
networkToLocalManga.await(sManga.toDomainManga(), sourceId)
|
||||
networkToLocalManga.await(sManga.toDomainManga(sourceId))
|
||||
} to metadata
|
||||
// SY <--
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ open class SourceFeedPresenter(
|
||||
.subscribeOn(Schedulers.io())
|
||||
.onErrorReturn { MangasPage(emptyList(), false) } // Ignore timeouts or other exceptions
|
||||
.map { it.mangas } // Get manga from search result.
|
||||
.map { list -> runBlocking { list.map { networkToLocalManga.await(it.toDomainManga(), source.id) } } } // Convert to local manga.
|
||||
.map { list -> runBlocking { list.map { networkToLocalManga.await(it.toDomainManga(source.id)) } } } // Convert to local manga.
|
||||
.map { list -> sourceFeed.withResults(list) }
|
||||
},
|
||||
5,
|
||||
|
@ -264,6 +264,6 @@ open class GlobalSearchPresenter(
|
||||
* @return a manga from the database.
|
||||
*/
|
||||
protected open suspend fun networkToLocalManga(sManga: SManga, sourceId: Long): DomainManga {
|
||||
return networkToLocalManga.await(sManga.toDomainManga(), sourceId)
|
||||
return networkToLocalManga.await(sManga.toDomainManga(sourceId))
|
||||
}
|
||||
}
|
||||
|
@ -594,7 +594,7 @@ class MangaInfoScreenModel(
|
||||
existingManga = getManga.await(mergedManga.url, mergedManga.source)
|
||||
}
|
||||
|
||||
mergedManga = networkToLocalManga.await(mergedManga, mergedManga.source)
|
||||
mergedManga = networkToLocalManga.await(mergedManga)
|
||||
|
||||
getCategories.await(originalMangaId)
|
||||
.let {
|
||||
|
@ -134,7 +134,6 @@ class GalleryAdder(
|
||||
source = source.id,
|
||||
url = cleanedMangaUrl,
|
||||
),
|
||||
source.id,
|
||||
)
|
||||
|
||||
// Fetch and copy details
|
||||
|
@ -44,7 +44,7 @@ class SmartSearchEngine(
|
||||
}.flatMap { it.await() }
|
||||
}
|
||||
|
||||
return eligibleManga.maxByOrNull { it.dist }?.manga?.toDomainManga()
|
||||
return eligibleManga.maxByOrNull { it.dist }?.manga?.toDomainManga(source.id)
|
||||
}
|
||||
|
||||
suspend fun normalSearch(source: CatalogueSource, title: String): Manga? {
|
||||
@ -68,7 +68,7 @@ class SmartSearchEngine(
|
||||
}
|
||||
}
|
||||
|
||||
return eligibleManga.maxByOrNull { it.dist }?.manga?.toDomainManga()
|
||||
return eligibleManga.maxByOrNull { it.dist }?.manga?.toDomainManga(source.id)
|
||||
}
|
||||
|
||||
private fun getSmartSearchQueries(cleanedTitle: String): List<String> {
|
||||
|
@ -33,7 +33,7 @@ class SmartSearchPresenter(
|
||||
val result = try {
|
||||
val resultManga = smartSearchEngine.smartSearch(source, config.origTitle)
|
||||
if (resultManga != null) {
|
||||
val localManga = networkToLocalManga.await(resultManga, source.id)
|
||||
val localManga = networkToLocalManga.await(resultManga)
|
||||
SearchResults.Found(localManga)
|
||||
} else {
|
||||
SearchResults.NotFound
|
||||
|
Loading…
x
Reference in New Issue
Block a user