From 36d8039e73a12eb689c96ad5748cad8ef4b3aa5c Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sat, 1 Sep 2018 19:01:32 -0400 Subject: [PATCH] #1211 - Sharing to new conversation doesn't show name/number --- .../com/moez/QKSMS/feature/compose/ComposeViewModel.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt index 38030358..10fabf24 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeViewModel.kt @@ -131,9 +131,15 @@ class ComposeViewModel @Inject constructor( .doOnNext { newState { copy(loading = false) } } .mergeWith(threadIdSubject) .switchMap { threadId -> + // Query the entire list of conversations and map from there, rather than + // directly querying the conversation from realm. If querying a single + // conversation and it doesn't exist yet, the realm query will never update conversationRepo.getConversations().asObservable() - .map { conversations -> conversations.filter { it.id == threadId } } - .map { conversations -> conversations.firstOrNull() ?: Conversation(id = threadId) } + .map { conversations -> + conversations.firstOrNull { it.id == threadId } + ?: conversationRepo.getOrCreateConversation(threadId) + ?: Conversation(id = threadId) + } } .mergeWith(initialConversation) .filter { conversation -> conversation.isLoaded }