mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-03 15:05:24 +00:00
Fix device linking
This commit is contained in:
parent
e6e5cb5adb
commit
45706b8e66
@ -3,6 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:background="@drawable/default_dialog_background_inset"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
@ -12,6 +13,7 @@
|
||||
android:paddingBottom="@dimen/medium_spacing">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/qrCodeImageViewContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/small_spacing"
|
||||
@ -24,6 +26,15 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.github.ybq.android.spinkit.SpinKitView
|
||||
style="@style/SpinKitView.DoubleBounce"
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:visibility="gone"
|
||||
app:SpinKit_Color="@color/text" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleTextView"
|
||||
android:layout_width="wrap_content"
|
||||
@ -56,6 +67,7 @@
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/buttonContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/large_spacing"
|
||||
|
@ -18,7 +18,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_centerInParent="true"
|
||||
app:SpinKit_Color="@color/text" />
|
||||
|
||||
<TextView
|
||||
|
@ -11,7 +11,6 @@ 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.ApplicationContext
|
||||
@ -21,13 +20,10 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.devicelist.Device
|
||||
import org.thoughtcrime.securesms.loki.dialogs.*
|
||||
import org.thoughtcrime.securesms.loki.protocol.EphemeralMessage
|
||||
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
|
||||
import org.thoughtcrime.securesms.loki.protocol.PushEphemeralMessageSendJob
|
||||
import org.thoughtcrime.securesms.loki.protocol.SyncMessagesProtocol
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.loki.api.LokiAPI
|
||||
import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI
|
||||
import org.whispersystems.signalservice.loki.protocol.multidevice.DeviceLink
|
||||
import java.util.*
|
||||
import kotlin.concurrent.schedule
|
||||
|
||||
@ -147,24 +143,17 @@ class LinkedDevicesActivity : PassphraseRequiredActionBarActivity, LoaderManager
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDeviceLinkRequestAuthorized(deviceLink: DeviceLink) {
|
||||
LokiFileServerAPI.shared.addDeviceLink(deviceLink).bind(LokiAPI.sharedContext) {
|
||||
MultiDeviceProtocol.signAndSendDeviceLinkMessage(this, deviceLink)
|
||||
}.success {
|
||||
TextSecurePreferences.setMultiDevice(this, true)
|
||||
SyncMessagesProtocol.syncAllClosedGroups(this@LinkedDevicesActivity)
|
||||
SyncMessagesProtocol.syncAllOpenGroups(this@LinkedDevicesActivity)
|
||||
Timer().schedule(4000) { // Not the best way to do this but the idea is to wait for the closed groups sync to go through first
|
||||
SyncMessagesProtocol.syncAllContacts(this@LinkedDevicesActivity)
|
||||
}
|
||||
}.successUi {
|
||||
LoaderManager.getInstance(this).restartLoader(0, null, this)
|
||||
}.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()
|
||||
override fun onDeviceLinkRequestAuthorized() {
|
||||
SyncMessagesProtocol.syncAllClosedGroups(this)
|
||||
SyncMessagesProtocol.syncAllOpenGroups(this)
|
||||
Timer().schedule(4000) { // Not the best way to do this but the idea is to wait for the closed groups sync to go through first
|
||||
SyncMessagesProtocol.syncAllContacts(this@LinkedDevicesActivity)
|
||||
}
|
||||
LoaderManager.getInstance(this).restartLoader(0, null, this)
|
||||
}
|
||||
|
||||
override fun onDeviceLinkAuthorizationFailed() {
|
||||
Toast.makeText(this, "Couldn't link device", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
override fun onDeviceLinkCanceled() {
|
||||
|
@ -11,12 +11,18 @@ import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import kotlinx.android.synthetic.main.dialog_link_device_master_mode.view.*
|
||||
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.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
|
||||
import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities
|
||||
import org.thoughtcrime.securesms.loki.utilities.QRCodeUtilities
|
||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
import org.whispersystems.signalservice.loki.api.LokiAPI
|
||||
import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI
|
||||
import org.whispersystems.signalservice.loki.crypto.MnemonicCodec
|
||||
import org.whispersystems.signalservice.loki.protocol.multidevice.DeviceLink
|
||||
import org.whispersystems.signalservice.loki.protocol.multidevice.DeviceLinkingSession
|
||||
@ -62,11 +68,36 @@ class LinkDeviceMasterModeDialog : DialogFragment(), DeviceLinkingSessionListene
|
||||
}
|
||||
|
||||
private fun authorizeDeviceLink() {
|
||||
val authorization = this.deviceLink ?: return
|
||||
delegate?.onDeviceLinkRequestAuthorized(authorization)
|
||||
val deviceLink = this.deviceLink ?: return
|
||||
DeviceLinkingSession.shared.stopListeningForLinkingRequests()
|
||||
DeviceLinkingSession.shared.removeListener(this)
|
||||
dismiss()
|
||||
Util.runOnMain {
|
||||
contentView.qrCodeImageViewContainer.visibility = View.GONE
|
||||
contentView.spinner.visibility = View.VISIBLE
|
||||
val titleTextViewLayoutParams = contentView.titleTextView.layoutParams as LinearLayout.LayoutParams
|
||||
titleTextViewLayoutParams.topMargin = toPx(24, resources)
|
||||
contentView.titleTextView.layoutParams = titleTextViewLayoutParams
|
||||
contentView.titleTextView.text = "Authorizing Device Link"
|
||||
contentView.explanationTextView.text = "Please wait while the device link is created. This can take up to a minute."
|
||||
contentView.mnemonicTextView.visibility = View.GONE
|
||||
contentView.buttonContainer.visibility = View.GONE
|
||||
contentView.cancelButton.visibility = View.GONE
|
||||
contentView.authorizeButton.visibility = View.GONE
|
||||
}
|
||||
LokiFileServerAPI.shared.addDeviceLink(deviceLink).bind(LokiAPI.sharedContext) {
|
||||
MultiDeviceProtocol.signAndSendDeviceLinkMessage(context!!, deviceLink)
|
||||
}.success {
|
||||
TextSecurePreferences.setMultiDevice(context!!, true)
|
||||
}.successUi {
|
||||
delegate?.onDeviceLinkRequestAuthorized()
|
||||
dismiss()
|
||||
}.fail {
|
||||
LokiFileServerAPI.shared.removeDeviceLink(deviceLink) // If this fails we have a problem
|
||||
DatabaseFactory.getLokiPreKeyBundleDatabase(context!!).removePreKeyBundle(deviceLink.slaveHexEncodedPublicKey)
|
||||
}.failUi {
|
||||
delegate?.onDeviceLinkAuthorizationFailed()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDeviceLinkCanceled() {
|
||||
@ -82,6 +113,7 @@ class LinkDeviceMasterModeDialog : DialogFragment(), DeviceLinkingSessionListene
|
||||
|
||||
interface LinkDeviceMasterModeDialogDelegate {
|
||||
|
||||
fun onDeviceLinkRequestAuthorized(authorization: DeviceLink)
|
||||
fun onDeviceLinkRequestAuthorized()
|
||||
fun onDeviceLinkAuthorizationFailed()
|
||||
fun onDeviceLinkCanceled()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user