mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 17:27:45 +00:00
Fix ui not being dismissed on message send failure.
Fix prekey bundle not being sent with the device pairing request.
This commit is contained in:
parent
72059328b3
commit
e07d8ddb52
@ -1204,10 +1204,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendBackgroundMessage(String contactHexEncodedPublicKey) {
|
private void sendBackgroundMessage(String contactHexEncodedPublicKey) {
|
||||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
Util.runOnMain(() -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
SignalServiceMessageSender messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender();
|
SignalServiceMessageSender messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender();
|
||||||
SignalServiceAddress address = new SignalServiceAddress(contactHexEncodedPublicKey);
|
SignalServiceAddress address = new SignalServiceAddress(contactHexEncodedPublicKey);
|
||||||
SignalServiceDataMessage message = new SignalServiceDataMessage(System.currentTimeMillis(), "");
|
SignalServiceDataMessage message = new SignalServiceDataMessage(System.currentTimeMillis(), "");
|
||||||
@ -1216,7 +1213,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d("Loki", "Failed to send background message to: " + contactHexEncodedPublicKey + ".");
|
Log.d("Loki", "Failed to send background message to: " + contactHexEncodedPublicKey + ".");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ import org.whispersystems.signalservice.loki.api.LokiDeviceLinkingSessionListene
|
|||||||
import org.whispersystems.signalservice.loki.api.LokiPairingAuthorisation
|
import org.whispersystems.signalservice.loki.api.LokiPairingAuthorisation
|
||||||
import org.whispersystems.signalservice.loki.api.LokiStorageAPI
|
import org.whispersystems.signalservice.loki.api.LokiStorageAPI
|
||||||
import org.whispersystems.signalservice.loki.utilities.retryIfNeeded
|
import org.whispersystems.signalservice.loki.utilities.retryIfNeeded
|
||||||
|
import org.thoughtcrime.securesms.util.Util
|
||||||
|
|
||||||
|
|
||||||
class DeviceLinkingDialog private constructor(private val context: Context, private val mode: DeviceLinkingView.Mode, private val delegate: DeviceLinkingDialogDelegate? = null): DeviceLinkingViewDelegate, LokiDeviceLinkingSessionListener {
|
class DeviceLinkingDialog private constructor(private val context: Context, private val mode: DeviceLinkingView.Mode, private val delegate: DeviceLinkingDialogDelegate? = null): DeviceLinkingViewDelegate, LokiDeviceLinkingSessionListener {
|
||||||
private lateinit var view: DeviceLinkingView
|
private lateinit var view: DeviceLinkingView
|
||||||
@ -93,14 +95,18 @@ class DeviceLinkingDialog private constructor(private val context: Context, priv
|
|||||||
|
|
||||||
// region Loki Device Session Listener
|
// region Loki Device Session Listener
|
||||||
override fun onDeviceLinkingRequestReceived(authorisation: LokiPairingAuthorisation) {
|
override fun onDeviceLinkingRequestReceived(authorisation: LokiPairingAuthorisation) {
|
||||||
|
Util.runOnMain {
|
||||||
view.requestUserAuthorization(authorisation)
|
view.requestUserAuthorization(authorisation)
|
||||||
|
}
|
||||||
|
|
||||||
// Stop listening to any more requests
|
// Stop listening to any more requests
|
||||||
LokiDeviceLinkingSession.shared.stopListeningForLinkingRequests()
|
LokiDeviceLinkingSession.shared.stopListeningForLinkingRequests()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDeviceLinkRequestAccepted(authorisation: LokiPairingAuthorisation) {
|
override fun onDeviceLinkRequestAccepted(authorisation: LokiPairingAuthorisation) {
|
||||||
|
Util.runOnMain {
|
||||||
view.onDeviceLinkAuthorized(authorisation)
|
view.onDeviceLinkAuthorized(authorisation)
|
||||||
|
}
|
||||||
|
|
||||||
// Stop listening to any more requests
|
// Stop listening to any more requests
|
||||||
LokiDeviceLinkingSession.shared.stopListeningForLinkingRequests()
|
LokiDeviceLinkingSession.shared.stopListeningForLinkingRequests()
|
||||||
|
@ -108,8 +108,6 @@ class DeviceLinkingView private constructor(context: Context, attrs: AttributeSe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pairingAuthorisation = authorisation
|
|
||||||
|
|
||||||
spinner.visibility = View.GONE
|
spinner.visibility = View.GONE
|
||||||
val titleTextViewLayoutParams = titleTextView.layoutParams as LayoutParams
|
val titleTextViewLayoutParams = titleTextView.layoutParams as LayoutParams
|
||||||
titleTextViewLayoutParams.topMargin = toPx(16, resources)
|
titleTextViewLayoutParams.topMargin = toPx(16, resources)
|
||||||
@ -120,6 +118,8 @@ class DeviceLinkingView private constructor(context: Context, attrs: AttributeSe
|
|||||||
val hexEncodedPublicKey = authorisation.secondaryDevicePubKey.removing05PrefixIfNeeded()
|
val hexEncodedPublicKey = authorisation.secondaryDevicePubKey.removing05PrefixIfNeeded()
|
||||||
mnemonicTextView.text = MnemonicCodec(languageFileDirectory).encode(hexEncodedPublicKey).split(" ").slice(0 until 3).joinToString(" ")
|
mnemonicTextView.text = MnemonicCodec(languageFileDirectory).encode(hexEncodedPublicKey).split(" ").slice(0 until 3).joinToString(" ")
|
||||||
authorizeButton.visibility = View.VISIBLE
|
authorizeButton.visibility = View.VISIBLE
|
||||||
|
|
||||||
|
this.pairingAuthorisation = authorisation
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun authorize() {
|
private fun authorize() {
|
||||||
|
@ -232,7 +232,7 @@ class SeedActivity : BaseActionBarActivity() {
|
|||||||
// Send the request to the other user
|
// Send the request to the other user
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
retryIfNeeded(3) {
|
retryIfNeeded(3) {
|
||||||
sendAuthorisationMessage(this@SeedActivity, authorisation.primaryDevicePubKey, authorisation)
|
sendAuthorisationMessage(this@SeedActivity, authorisation.primaryDevicePubKey, authorisation).get()
|
||||||
}.failUi {
|
}.failUi {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
resetRegistration()
|
resetRegistration()
|
||||||
|
@ -6,6 +6,7 @@ import android.os.Looper
|
|||||||
import nl.komponents.kovenant.Promise
|
import nl.komponents.kovenant.Promise
|
||||||
import nl.komponents.kovenant.deferred
|
import nl.komponents.kovenant.deferred
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
import org.thoughtcrime.securesms.logging.Log
|
import org.thoughtcrime.securesms.logging.Log
|
||||||
import org.whispersystems.libsignal.util.guava.Optional
|
import org.whispersystems.libsignal.util.guava.Optional
|
||||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair
|
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair
|
||||||
@ -14,15 +15,19 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
|||||||
import org.whispersystems.signalservice.loki.api.LokiPairingAuthorisation
|
import org.whispersystems.signalservice.loki.api.LokiPairingAuthorisation
|
||||||
|
|
||||||
fun sendAuthorisationMessage(context: Context, contactHexEncodedPublicKey: String, authorisation: LokiPairingAuthorisation): Promise<Unit, Exception> {
|
fun sendAuthorisationMessage(context: Context, contactHexEncodedPublicKey: String, authorisation: LokiPairingAuthorisation): Promise<Unit, Exception> {
|
||||||
val deferred = deferred<Unit, Exception>()
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
|
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
|
||||||
val address = SignalServiceAddress(contactHexEncodedPublicKey)
|
val address = SignalServiceAddress(contactHexEncodedPublicKey)
|
||||||
|
val message = SignalServiceDataMessage.newBuilder().withBody("").withPairingAuthorisation(authorisation)
|
||||||
|
|
||||||
// A REQUEST should always act as a friend request. A GRANT should always be replying back as a normal message.
|
// A REQUEST should always act as a friend request. A GRANT should always be replying back as a normal message.
|
||||||
val message = SignalServiceDataMessage.newBuilder().withBody("").withPairingAuthorisation(authorisation).asFriendRequest(authorisation.type == LokiPairingAuthorisation.Type.REQUEST).build()
|
if (authorisation.type == LokiPairingAuthorisation.Type.REQUEST) {
|
||||||
try {
|
val preKeyBundle = DatabaseFactory.getLokiPreKeyBundleDatabase(context).generatePreKeyBundle(address.number)
|
||||||
|
message.asFriendRequest(true).withPreKeyBundle(preKeyBundle)
|
||||||
|
}
|
||||||
|
|
||||||
|
return try {
|
||||||
Log.d("Loki", "Sending authorisation message to $contactHexEncodedPublicKey")
|
Log.d("Loki", "Sending authorisation message to $contactHexEncodedPublicKey")
|
||||||
val result = messageSender.sendMessage(0, address, Optional.absent<UnidentifiedAccessPair>(), message)
|
val result = messageSender.sendMessage(0, address, Optional.absent<UnidentifiedAccessPair>(), message.build())
|
||||||
if (result.success == null) {
|
if (result.success == null) {
|
||||||
val exception = when {
|
val exception = when {
|
||||||
result.isNetworkFailure -> "Failed to send authorisation message because of a Network Error"
|
result.isNetworkFailure -> "Failed to send authorisation message because of a Network Error"
|
||||||
@ -31,13 +36,9 @@ fun sendAuthorisationMessage(context: Context, contactHexEncodedPublicKey: Strin
|
|||||||
|
|
||||||
throw Exception(exception)
|
throw Exception(exception)
|
||||||
}
|
}
|
||||||
|
Promise.ofSuccess(Unit)
|
||||||
deferred.resolve(Unit)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.d("Loki", "Failed to send authorisation message to: $contactHexEncodedPublicKey.")
|
Log.d("Loki", "Failed to send authorisation message to: $contactHexEncodedPublicKey.")
|
||||||
deferred.reject(e)
|
Promise.ofFail(e)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return deferred.promise
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user