Cleanup UpdatesPresenter deleteChapters (#8273)

This commit is contained in:
AntsyLich 2022-10-22 22:58:14 +06:00 committed by GitHub
parent d0bff298b7
commit 4a244a598b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -254,13 +254,14 @@ class UpdatesPresenter(
*/
fun deleteChapters(updatesItem: List<UpdatesItem>) {
presenterScope.launchNonCancellable {
val groupedUpdates = updatesItem.groupBy { it.update.mangaId }.values
groupedUpdates.flatMap { updates ->
val mangaId = updates.first().update.mangaId
val manga = getManga.await(mangaId) ?: return@flatMap emptyList()
val source = sourceManager.get(manga.source) ?: return@flatMap emptyList()
updatesItem
.groupBy { it.update.mangaId }
.entries
.forEach { (mangaId, updates) ->
val manga = getManga.await(mangaId) ?: return@forEach
val source = sourceManager.get(manga.source) ?: return@forEach
val chapters = updates.mapNotNull { getChapter.await(it.update.chapterId)?.toDbChapter() }
downloadManager.deleteChapters(chapters, manga, source).mapNotNull { it.id }
downloadManager.deleteChapters(chapters, manga, source)
}
}
}