Skip to content

Instantly share code, notes, and snippets.

@Dima564
Created November 1, 2016 11:33
Show Gist options
  • Save Dima564/4600b03359fbdd5ed1bdfec9a2c73481 to your computer and use it in GitHub Desktop.
Save Dima564/4600b03359fbdd5ed1bdfec9a2c73481 to your computer and use it in GitHub Desktop.
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