mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Fix device linking blocking the main promise thread.
This commit is contained in:
parent
7c89f5ce1a
commit
dd0b9c80b0
@ -12,6 +12,7 @@ import android.view.View
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import kotlinx.android.synthetic.main.activity_linked_devices.*
|
import kotlinx.android.synthetic.main.activity_linked_devices.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
|
import nl.komponents.kovenant.functional.bind
|
||||||
import nl.komponents.kovenant.ui.failUi
|
import nl.komponents.kovenant.ui.failUi
|
||||||
import nl.komponents.kovenant.ui.successUi
|
import nl.komponents.kovenant.ui.successUi
|
||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
@ -23,6 +24,7 @@ import org.thoughtcrime.securesms.loki.signAndSendDeviceLinkMessage
|
|||||||
import org.thoughtcrime.securesms.sms.MessageSender
|
import org.thoughtcrime.securesms.sms.MessageSender
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||||
import org.whispersystems.signalservice.loki.api.DeviceLink
|
import org.whispersystems.signalservice.loki.api.DeviceLink
|
||||||
|
import org.whispersystems.signalservice.loki.api.LokiAPI
|
||||||
import org.whispersystems.signalservice.loki.api.LokiFileServerAPI
|
import org.whispersystems.signalservice.loki.api.LokiFileServerAPI
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.schedule
|
import kotlin.concurrent.schedule
|
||||||
@ -143,23 +145,20 @@ class LinkedDevicesActivity : PassphraseRequiredActionBarActivity, LoaderManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDeviceLinkRequestAuthorized(deviceLink: DeviceLink) {
|
override fun onDeviceLinkRequestAuthorized(deviceLink: DeviceLink) {
|
||||||
LokiFileServerAPI.shared.addDeviceLink(deviceLink).success {
|
LokiFileServerAPI.shared.addDeviceLink(deviceLink).bind(LokiAPI.sharedWorkContext) {
|
||||||
signAndSendDeviceLinkMessage(this, deviceLink).successUi {
|
signAndSendDeviceLinkMessage(this, deviceLink)
|
||||||
LoaderManager.getInstance(this).restartLoader(0, null, this)
|
}.successUi {
|
||||||
}.success {
|
LoaderManager.getInstance(this).restartLoader(0, null, this)
|
||||||
TextSecurePreferences.setMultiDevice(this, true)
|
}.success {
|
||||||
Timer().schedule(4000) {
|
TextSecurePreferences.setMultiDevice(this, true)
|
||||||
MessageSender.syncAllGroups(this@LinkedDevicesActivity)
|
Timer().schedule(4000) {
|
||||||
MessageSender.syncAllContacts(this@LinkedDevicesActivity, Address.fromSerialized(deviceLink.slaveHexEncodedPublicKey))
|
MessageSender.syncAllGroups(this@LinkedDevicesActivity)
|
||||||
}
|
MessageSender.syncAllContacts(this@LinkedDevicesActivity, Address.fromSerialized(deviceLink.slaveHexEncodedPublicKey))
|
||||||
}.failUi {
|
|
||||||
Toast.makeText(this, "Couldn't link device", Toast.LENGTH_LONG).show()
|
|
||||||
}.fail {
|
|
||||||
LokiFileServerAPI.shared.removeDeviceLink(deviceLink) // If this fails we have a problem
|
|
||||||
DatabaseFactory.getLokiPreKeyBundleDatabase(this).removePreKeyBundle(deviceLink.slaveHexEncodedPublicKey)
|
|
||||||
}
|
}
|
||||||
}.failUi {
|
}.fail {
|
||||||
|
LokiFileServerAPI.shared.removeDeviceLink(deviceLink) // If this fails we have a problem
|
||||||
DatabaseFactory.getLokiPreKeyBundleDatabase(this).removePreKeyBundle(deviceLink.slaveHexEncodedPublicKey)
|
DatabaseFactory.getLokiPreKeyBundleDatabase(this).removePreKeyBundle(deviceLink.slaveHexEncodedPublicKey)
|
||||||
|
}.failUi {
|
||||||
Toast.makeText(this, "Couldn't link device", Toast.LENGTH_LONG).show()
|
Toast.makeText(this, "Couldn't link device", Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user