瀏覽代碼

Set source properly when creating manga entries

Fixes #8333
arkon 2 年之前
父節點
當前提交
cac80daa71

+ 5 - 5
app/src/main/java/eu/kanade/domain/manga/interactor/NetworkToLocalManga.kt

@@ -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)
     }
 }

+ 2 - 1
app/src/main/java/eu/kanade/domain/manga/model/Manga.kt

@@ -232,7 +232,7 @@ fun Manga.toMangaUpdate(): MangaUpdate {
     )
 }
 
-fun SManga.toDomainManga(): Manga {
+fun SManga.toDomainManga(sourceId: Long): Manga {
     return Manga.create().copy(
         url = url,
         title = title,
@@ -244,6 +244,7 @@ fun SManga.toDomainManga(): Manga {
         thumbnailUrl = thumbnail_url,
         updateStrategy = update_strategy,
         initialized = initialized,
+        source = sourceId,
     )
 }
 

+ 6 - 12
app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt

@@ -32,13 +32,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>()
 
@@ -56,7 +50,7 @@ class SourceManager(
                             registerStubSource(it.toSourceData())
                         }
                     }
-                    sourcesMap = mutableMap
+                    sourcesMapFlow.value = mutableMap
                 }
         }
 
@@ -72,18 +66,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 }

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt

@@ -131,7 +131,7 @@ open class BrowseSourcePresenter(
                 .map {
                     it.map { sManga ->
                         withIOContext {
-                            networkToLocalManga.await(sManga.toDomainManga(), sourceId)
+                            networkToLocalManga.await(sManga.toDomainManga(sourceId))
                         }
                     }
                 }

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt

@@ -260,6 +260,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))
     }
 }