forked from upstream-mirrors/quik
Fixed conversation loading
This commit is contained in:
@@ -49,6 +49,11 @@ class ComposeViewModel(threadId: Long) : QkViewModel<ComposeView, ComposeState>(
|
|||||||
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
||||||
.doOnNext { contacts -> newState { it.copy(selectedContacts = contacts) } }
|
.doOnNext { contacts -> newState { it.copy(selectedContacts = contacts) } }
|
||||||
|
|
||||||
|
val initialConversation: Observable<Conversation> = when(threadId) {
|
||||||
|
0L -> Observable.empty()
|
||||||
|
else -> messageRepo.getConversationAsync(threadId).asObservable()
|
||||||
|
}
|
||||||
|
|
||||||
// Map the selected contacts to a conversation so that we can display the message history
|
// Map the selected contacts to a conversation so that we can display the message history
|
||||||
val selectedConversation = selectedContacts
|
val selectedConversation = selectedContacts
|
||||||
.map { contacts -> contacts.map { it.address } }
|
.map { contacts -> contacts.map { it.address } }
|
||||||
@@ -56,16 +61,15 @@ class ComposeViewModel(threadId: Long) : QkViewModel<ComposeView, ComposeState>(
|
|||||||
|
|
||||||
// Merges two potential conversation sources (threadId from constructor and contact selection) into a single
|
// Merges two potential conversation sources (threadId from constructor and contact selection) into a single
|
||||||
// stream of conversations. If the conversation was deleted, notify the activity to shut down
|
// stream of conversations. If the conversation was deleted, notify the activity to shut down
|
||||||
conversation = Observable.just(messageRepo.getConversation(threadId) ?: Conversation())
|
conversation = initialConversation
|
||||||
.filter { conversation -> conversation.id != 0L }
|
|
||||||
.filter { conversation -> conversation.isLoaded }
|
.filter { conversation -> conversation.isLoaded }
|
||||||
.filter { conversation ->
|
.doOnNext { conversation ->
|
||||||
if (!conversation.isValid) {
|
if (!conversation.isValid) {
|
||||||
newState { it.copy(hasError = true) }
|
newState { it.copy(hasError = true) }
|
||||||
return@filter false
|
|
||||||
}
|
}
|
||||||
return@filter true
|
|
||||||
}
|
}
|
||||||
|
.filter { conversation -> conversation.isValid }
|
||||||
|
.take(1)
|
||||||
.mergeWith(selectedConversation)
|
.mergeWith(selectedConversation)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.doOnNext { conversation ->
|
.doOnNext { conversation ->
|
||||||
|
|||||||
Reference in New Issue
Block a user