|
|
|
@ -12,11 +12,12 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|
|
|
|
import kotlinx.coroutines.flow.asSharedFlow
|
|
|
|
|
import kotlinx.coroutines.flow.asStateFlow
|
|
|
|
|
import kotlinx.coroutines.flow.update
|
|
|
|
|
import kotlinx.coroutines.isActive
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import kotlinx.coroutines.withTimeout
|
|
|
|
|
import network.loki.messenger.R
|
|
|
|
|
import org.session.libsession.snode.SnodeAPI
|
|
|
|
|
import org.session.libsignal.utilities.PublicKeyValidation
|
|
|
|
|
import org.session.libsignal.utilities.timeout
|
|
|
|
|
import org.thoughtcrime.securesms.ui.GetString
|
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
import kotlin.coroutines.cancellation.CancellationException
|
|
|
|
@ -71,15 +72,10 @@ internal class NewMessageViewModel @Inject constructor(
|
|
|
|
|
|
|
|
|
|
loadOnsJob = viewModelScope.launch(Dispatchers.IO) {
|
|
|
|
|
try {
|
|
|
|
|
val publicKey = withTimeout(30.seconds) { SnodeAPI.getSessionID(ons).get() }
|
|
|
|
|
onPublicKey(publicKey)
|
|
|
|
|
} catch (e: TimeoutCancellationException) {
|
|
|
|
|
onError(e)
|
|
|
|
|
} catch (e: CancellationException) {
|
|
|
|
|
// Attempting to just ignore internal JobCancellationException, which is called
|
|
|
|
|
// when we cancel the job, state update is handled there.
|
|
|
|
|
val publicKey = SnodeAPI.getSessionID(ons).timeout(30_000).get()
|
|
|
|
|
if (isActive) onPublicKey(publicKey)
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
onError(e)
|
|
|
|
|
if (isActive) onError(e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|