From 4a244a598bd8caceaab76ae2c851d8e8ef04ed21 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sat, 22 Oct 2022 22:58:14 +0600 Subject: [PATCH] Cleanup UpdatesPresenter `deleteChapters` (#8273) --- .../ui/recent/updates/UpdatesPresenter.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt index 4f58cd3c81..953afc2e4d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt @@ -254,14 +254,15 @@ class UpdatesPresenter( */ fun deleteChapters(updatesItem: List) { 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() - val chapters = updates.mapNotNull { getChapter.await(it.update.chapterId)?.toDbChapter() } - downloadManager.deleteChapters(chapters, manga, source).mapNotNull { it.id } - } + 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) + } } }