소스 검색

Cleanup UpdatesPresenter `deleteChapters` (#8273)

AntsyLich 2 년 전
부모
커밋
4a244a598b
1개의 변경된 파일9개의 추가작업 그리고 8개의 파일을 삭제
  1. 9 8
      app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt

+ 9 - 8
app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt

@@ -254,14 +254,15 @@ 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()
-                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)
+                }
         }
     }