Fix crash when reducing empty collection

This commit is contained in:
Benoit Marty 2019-06-04 15:12:09 +02:00
parent 647a066c90
commit ab6220a4cb

View File

@ -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 }