Fix voice note crash when future failed.

main
Cody Henthorne 2023-01-05 12:12:03 -05:00
rodzic a835e5d143
commit 73e46053f0
1 zmienionych plików z 15 dodań i 2 usunięć

Wyświetl plik

@ -16,6 +16,7 @@ import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.util.Base64
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture
import org.thoughtcrime.securesms.util.rx.RxStore
import java.util.concurrent.ExecutionException
/**
* ViewModel responsible for holding Voice Note draft state. The intention is to allow
@ -46,8 +47,20 @@ class DraftViewModel @JvmOverloads constructor(
}
fun saveEphemeralVoiceNoteDraft(voiceNoteDraftFuture: ListenableFuture<VoiceNoteDraft>) {
store.update {
saveDrafts(it.copy(voiceNoteDraft = voiceNoteDraftFuture.get().asDraft()))
store.update { draftState ->
val draft: VoiceNoteDraft? = try {
voiceNoteDraftFuture.get()
} catch (e: ExecutionException) {
null
} catch (e: InterruptedException) {
null
}
if (draft != null) {
saveDrafts(draftState.copy(voiceNoteDraft = draft.asDraft()))
} else {
draftState
}
}
}