From dd0b9c80b017d64156eaa4855c960f0431b59ba2 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 26 Feb 2020 16:56:07 +1100 Subject: [PATCH] Fix device linking blocking the main promise thread. --- .../activities/LinkedDevicesActivity.kt | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesActivity.kt index 759362b91c..1def8899cd 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesActivity.kt @@ -12,6 +12,7 @@ import android.view.View import android.widget.Toast import kotlinx.android.synthetic.main.activity_linked_devices.* import network.loki.messenger.R +import nl.komponents.kovenant.functional.bind import nl.komponents.kovenant.ui.failUi import nl.komponents.kovenant.ui.successUi 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.util.TextSecurePreferences import org.whispersystems.signalservice.loki.api.DeviceLink +import org.whispersystems.signalservice.loki.api.LokiAPI import org.whispersystems.signalservice.loki.api.LokiFileServerAPI import java.util.* import kotlin.concurrent.schedule @@ -143,23 +145,20 @@ class LinkedDevicesActivity : PassphraseRequiredActionBarActivity, LoaderManager } override fun onDeviceLinkRequestAuthorized(deviceLink: DeviceLink) { - LokiFileServerAPI.shared.addDeviceLink(deviceLink).success { - signAndSendDeviceLinkMessage(this, deviceLink).successUi { - LoaderManager.getInstance(this).restartLoader(0, null, this) - }.success { - TextSecurePreferences.setMultiDevice(this, true) - Timer().schedule(4000) { - 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) + LokiFileServerAPI.shared.addDeviceLink(deviceLink).bind(LokiAPI.sharedWorkContext) { + signAndSendDeviceLinkMessage(this, deviceLink) + }.successUi { + LoaderManager.getInstance(this).restartLoader(0, null, this) + }.success { + TextSecurePreferences.setMultiDevice(this, true) + Timer().schedule(4000) { + MessageSender.syncAllGroups(this@LinkedDevicesActivity) + MessageSender.syncAllContacts(this@LinkedDevicesActivity, Address.fromSerialized(deviceLink.slaveHexEncodedPublicKey)) } - }.failUi { + }.fail { + LokiFileServerAPI.shared.removeDeviceLink(deviceLink) // If this fails we have a problem DatabaseFactory.getLokiPreKeyBundleDatabase(this).removePreKeyBundle(deviceLink.slaveHexEncodedPublicKey) + }.failUi { Toast.makeText(this, "Couldn't link device", Toast.LENGTH_LONG).show() } }