Fix merged manga chapters and merged manga filtered scanlators
This commit is contained in:
parent
d82b2919f8
commit
25f94e4500
@ -21,4 +21,16 @@ class GetAvailableScanlators(
|
||||
return repository.getScanlatorsByMangaIdAsFlow(mangaId)
|
||||
.map { it.cleanupAvailableScanlators() }
|
||||
}
|
||||
|
||||
// SY -->
|
||||
suspend fun awaitMerge(mangaId: Long): Set<String> {
|
||||
return repository.getScanlatorsByMergeId(mangaId)
|
||||
.cleanupAvailableScanlators()
|
||||
}
|
||||
|
||||
fun subscribeMerge(mangaId: Long): Flow<Set<String>> {
|
||||
return repository.getScanlatorsByMergeIdAsFlow(mangaId)
|
||||
.map { it.cleanupAvailableScanlators() }
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
|
@ -71,7 +71,10 @@ import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.flatMapConcat
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.update
|
||||
@ -341,6 +344,20 @@ class MangaScreenModel(
|
||||
screenModelScope.launchIO {
|
||||
getAvailableScanlators.subscribe(mangaId)
|
||||
.distinctUntilChanged()
|
||||
// SY -->
|
||||
.combine(
|
||||
state.map { (it as? State.Success)?.manga }
|
||||
.distinctUntilChangedBy { it?.source }
|
||||
.flatMapConcat {
|
||||
if (it?.source == MERGED_SOURCE_ID) {
|
||||
getAvailableScanlators.subscribeMerge(mangaId)
|
||||
} else {
|
||||
flowOf(emptySet())
|
||||
}
|
||||
}
|
||||
) { mangaScanlators, mergeScanlators ->
|
||||
mangaScanlators + mergeScanlators
|
||||
} // SY <--
|
||||
.collectLatest { availableScanlators ->
|
||||
updateSuccessState {
|
||||
it.copy(availableScanlators = availableScanlators.toImmutableSet())
|
||||
@ -381,7 +398,13 @@ class MangaScreenModel(
|
||||
source = source,
|
||||
isFromSource = isFromSource,
|
||||
chapters = chapters,
|
||||
availableScanlators = getAvailableScanlators.await(mangaId).toImmutableSet(),
|
||||
// SY -->
|
||||
availableScanlators = if (manga.source == MERGED_SOURCE_ID) {
|
||||
getAvailableScanlators.awaitMerge(mangaId)
|
||||
} else {
|
||||
getAvailableScanlators.await(mangaId)
|
||||
}.toImmutableSet(),
|
||||
// SY <--
|
||||
excludedScanlators = getExcludedScanlators.await(mangaId).toImmutableSet(),
|
||||
isRefreshingData = needRefreshInfo || needRefreshChapter,
|
||||
dialog = null,
|
||||
|
@ -151,5 +151,17 @@ class ChapterRepositoryImpl(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getScanlatorsByMergeId(mangaId: Long): List<String> {
|
||||
return handler.awaitList {
|
||||
chaptersQueries.getScanlatorsByMergeId(mangaId) { it.orEmpty() }
|
||||
}
|
||||
}
|
||||
|
||||
override fun getScanlatorsByMergeIdAsFlow(mangaId: Long): Flow<List<String>> {
|
||||
return handler.subscribeToList {
|
||||
chaptersQueries.getScanlatorsByMergeId(mangaId) { it.orEmpty() }
|
||||
}
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
|
@ -71,20 +71,28 @@ AND manga_id = :mangaId;
|
||||
|
||||
getMergedChaptersByMangaId:
|
||||
SELECT C.*
|
||||
FROM chapters C
|
||||
JOIN (
|
||||
SELECT manga_id FROM merged WHERE merge_id = :mangaId
|
||||
FROM (
|
||||
SELECT manga_id,merge_id FROM merged WHERE merge_id = :mangaId
|
||||
) AS M
|
||||
JOIN chapters C
|
||||
ON C.manga_id = M.manga_id
|
||||
LEFT JOIN excluded_scanlators ES
|
||||
ON C.manga_id = ES.manga_id
|
||||
ON M.merge_id = ES.manga_id
|
||||
AND C.scanlator = ES.scanlator
|
||||
WHERE C.manga_id = :mangaId
|
||||
WHERE M.merge_id = :mangaId
|
||||
AND (
|
||||
:applyScanlatorFilter = 0
|
||||
OR ES.scanlator IS NULL
|
||||
);
|
||||
|
||||
getScanlatorsByMergeId:
|
||||
SELECT scanlator
|
||||
FROM (
|
||||
SELECT manga_id FROM merged WHERE merge_id = ?
|
||||
) AS M
|
||||
JOIN chapters
|
||||
ON chapters.manga_id = M.manga_id;
|
||||
|
||||
removeChaptersWithIds:
|
||||
DELETE FROM chapters
|
||||
WHERE _id IN :chapterIds;
|
||||
|
@ -37,5 +37,9 @@ interface ChapterRepository {
|
||||
mangaId: Long,
|
||||
applyScanlatorFilter: Boolean = false,
|
||||
): Flow<List<Chapter>>
|
||||
|
||||
suspend fun getScanlatorsByMergeId(mangaId: Long): List<String>
|
||||
|
||||
fun getScanlatorsByMergeIdAsFlow(mangaId: Long): Flow<List<String>>
|
||||
// SY <--
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user