Skip to content

Commit

Permalink
Fix crash when saving draft in QkReply
Browse files Browse the repository at this point in the history
  • Loading branch information
moezbhatti committed Jul 1, 2018
1 parent 117cbc4 commit c591300
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,18 @@ class QkReplyViewModel @Inject constructor(
.autoDisposable(view.scope())
.subscribe { remaining -> newState { copy(remaining = remaining) } }

// This allows the conversation to be mapped to a threadId in the correct thread
val safeThreadId = conversation.map { it.takeIf { it.isValid }?.id ?: -1 }

// Update the draft whenever the text is changed
view.textChangedIntent
.debounce(100, TimeUnit.MILLISECONDS)
.map { draft -> draft.toString() }
.observeOn(Schedulers.io())
.withLatestFrom(conversation.map { it.id }) { draft, threadId ->
conversationRepo.saveDraft(threadId, draft)
}
.withLatestFrom(safeThreadId) { draft, threadId -> Pair(draft, threadId) }
.filter { (_, threadId) -> threadId != -1L }
.autoDisposable(view.scope())
.subscribe()
.subscribe { (draft, threadId) -> conversationRepo.saveDraft(threadId, draft) }

// Toggle to the next sim slot
view.changeSimIntent
Expand Down

0 comments on commit c591300

Please sign in to comment.