Created
November 1, 2016 11:33
-
-
Save Dima564/4600b03359fbdd5ed1bdfec9a2c73481 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun getNumberOfAttachmentsInGroupConvesationsFun() { | |
return getCount({conv -> conv.groupId != null}, {it -> it.type == MessageType.ATTACHMENT && it.unread}) | |
} | |
private fun getUnreadCountFromUsersFun() { | |
return getCount({conv -> conv.recipientId != null}, {message -> message.unread}) | |
} | |
private fun getTotalNumberOfMessages() = getCount({true}, {true}) | |
private fun getCount(convFilter: (Conversation) -> Boolean, messageFilter: (Message) -> Boolean) { | |
datasource.getConversations() | |
.filter(convFilter) | |
.flatMap { it.messages } | |
.filter(messageFilter) | |
.fold(0, { count, message -> count + 1}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment