forked from upstream-mirrors/quik
Fix crash when saving draft in QkReply
This commit is contained in:
@@ -179,16 +179,18 @@ class QkReplyViewModel @Inject constructor(
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { remaining -> newState { copy(remaining = remaining) } }
|
.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
|
// Update the draft whenever the text is changed
|
||||||
view.textChangedIntent
|
view.textChangedIntent
|
||||||
.debounce(100, TimeUnit.MILLISECONDS)
|
.debounce(100, TimeUnit.MILLISECONDS)
|
||||||
.map { draft -> draft.toString() }
|
.map { draft -> draft.toString() }
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.withLatestFrom(conversation.map { it.id }) { draft, threadId ->
|
.withLatestFrom(safeThreadId) { draft, threadId -> Pair(draft, threadId) }
|
||||||
conversationRepo.saveDraft(threadId, draft)
|
.filter { (_, threadId) -> threadId != -1L }
|
||||||
}
|
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe()
|
.subscribe { (draft, threadId) -> conversationRepo.saveDraft(threadId, draft) }
|
||||||
|
|
||||||
// Toggle to the next sim slot
|
// Toggle to the next sim slot
|
||||||
view.changeSimIntent
|
view.changeSimIntent
|
||||||
|
|||||||
Reference in New Issue
Block a user