Group observables for modifying contact selection

This commit is contained in:
Moez Bhatti
2017-11-29 08:55:56 -05:00
parent 4d1a85d5dc
commit 7b95323a0e
@@ -99,13 +99,11 @@ class ComposeViewModel(threadId: Long) : QkViewModel<ComposeView, ComposeState>(
.observeOn(AndroidSchedulers.mainThread())
.subscribe { contacts -> newState { it.copy(contacts = contacts) } }
intents += view.chipDeletedIntent.subscribe { contact ->
contactsReducer.onNext { contacts -> contacts.filterNot { it == contact } }
}
intents += view.chipSelectedIntent.subscribe { contact ->
contactsReducer.onNext { contacts -> contacts.toMutableList().apply { add(contact) } }
}
intents += Observable.merge(
view.chipDeletedIntent.map { contact -> { contacts: List<Contact> -> contacts.filterNot { it == contact } } },
view.chipSelectedIntent.map { contact -> { contacts: List<Contact> -> contacts.toMutableList().apply { add(contact) } } })
.subscribe { reducer -> contactsReducer.onNext { reducer(it) } }
intents += view.textChangedIntent.subscribe { text ->
newState { it.copy(draft = text.toString(), canSend = text.isNotEmpty()) }