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