From ab6220a4cb081d6ed6ba9fa231faca6d23d3fb68 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 4 Jun 2019 15:12:09 +0200 Subject: [PATCH] Fix crash when reducing empty collection --- .../riotredesign/features/home/HomeDetailViewModel.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeDetailViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeDetailViewModel.kt index 8b6b773495..9e36dfc162 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeDetailViewModel.kt @@ -51,7 +51,9 @@ class HomeDetailViewModel(initialState: HomeDetailViewState, val peopleNotifications = summaries .filter { it.isDirect } .map { it.notificationCount } - .reduce { acc, i -> acc + i } + .takeIf { it.isNotEmpty() } + ?.reduce { acc, i -> acc + i } + ?: 0 val peopleHasHighlight = summaries .filter { it.isDirect } .any { it.highlightCount > 0 } @@ -59,7 +61,9 @@ class HomeDetailViewModel(initialState: HomeDetailViewState, val roomsNotifications = summaries .filter { !it.isDirect } .map { it.notificationCount } - .reduce { acc, i -> acc + i } + .takeIf { it.isNotEmpty() } + ?.reduce { acc, i -> acc + i } + ?: 0 val roomsHasHighlight = summaries .filter { !it.isDirect } .any { it.highlightCount > 0 }