mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +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) {
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Util.runOnMain(() -> {
|
||||
SignalServiceMessageSender messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender();
|
||||
SignalServiceAddress address = new SignalServiceAddress(contactHexEncodedPublicKey);
|
||||
SignalServiceDataMessage message = new SignalServiceDataMessage(System.currentTimeMillis(), "");
|
||||
@ -1216,7 +1213,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
} catch (Exception e) {
|
||||
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.LokiStorageAPI
|
||||
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 {
|
||||
private lateinit var view: DeviceLinkingView
|
||||
@ -93,14 +95,18 @@ class DeviceLinkingDialog private constructor(private val context: Context, priv
|
||||
|
||||
// region Loki Device Session Listener
|
||||
override fun onDeviceLinkingRequestReceived(authorisation: LokiPairingAuthorisation) {
|
||||
Util.runOnMain {
|
||||
view.requestUserAuthorization(authorisation)
|
||||
}
|
||||
|
||||
// Stop listening to any more requests
|
||||
LokiDeviceLinkingSession.shared.stopListeningForLinkingRequests()
|
||||
}
|
||||
|
||||
override fun onDeviceLinkRequestAccepted(authorisation: LokiPairingAuthorisation) {
|
||||
Util.runOnMain {
|
||||
view.onDeviceLinkAuthorized(authorisation)
|
||||
}
|
||||
|
||||
// Stop listening to any more requests
|
||||
LokiDeviceLinkingSession.shared.stopListeningForLinkingRequests()
|
||||
|
@ -108,8 +108,6 @@ class DeviceLinkingView private constructor(context: Context, attrs: AttributeSe
|
||||
return
|
||||
}
|
||||
|
||||
this.pairingAuthorisation = authorisation
|
||||
|
||||
spinner.visibility = View.GONE
|
||||
val titleTextViewLayoutParams = titleTextView.layoutParams as LayoutParams
|
||||
titleTextViewLayoutParams.topMargin = toPx(16, resources)
|
||||
@ -120,6 +118,8 @@ class DeviceLinkingView private constructor(context: Context, attrs: AttributeSe
|
||||
val hexEncodedPublicKey = authorisation.secondaryDevicePubKey.removing05PrefixIfNeeded()
|
||||
mnemonicTextView.text = MnemonicCodec(languageFileDirectory).encode(hexEncodedPublicKey).split(" ").slice(0 until 3).joinToString(" ")
|
||||
authorizeButton.visibility = View.VISIBLE
|
||||
|
||||
this.pairingAuthorisation = authorisation
|
||||
}
|
||||
|
||||
private fun authorize() {
|
||||
|
@ -232,7 +232,7 @@ class SeedActivity : BaseActionBarActivity() {
|
||||
// Send the request to the other user
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
retryIfNeeded(3) {
|
||||
sendAuthorisationMessage(this@SeedActivity, authorisation.primaryDevicePubKey, authorisation)
|
||||
sendAuthorisationMessage(this@SeedActivity, authorisation.primaryDevicePubKey, authorisation).get()
|
||||
}.failUi {
|
||||
dialog.dismiss()
|
||||
resetRegistration()
|
||||
|
@ -6,6 +6,7 @@ import android.os.Looper
|
||||
import nl.komponents.kovenant.Promise
|
||||
import nl.komponents.kovenant.deferred
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.logging.Log
|
||||
import org.whispersystems.libsignal.util.guava.Optional
|
||||
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
|
||||
|
||||
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 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.
|
||||
val message = SignalServiceDataMessage.newBuilder().withBody("").withPairingAuthorisation(authorisation).asFriendRequest(authorisation.type == LokiPairingAuthorisation.Type.REQUEST).build()
|
||||
try {
|
||||
if (authorisation.type == LokiPairingAuthorisation.Type.REQUEST) {
|
||||
val preKeyBundle = DatabaseFactory.getLokiPreKeyBundleDatabase(context).generatePreKeyBundle(address.number)
|
||||
message.asFriendRequest(true).withPreKeyBundle(preKeyBundle)
|
||||
}
|
||||
|
||||
return try {
|
||||
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) {
|
||||
val exception = when {
|
||||
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)
|
||||
}
|
||||
|
||||
deferred.resolve(Unit)
|
||||
Promise.ofSuccess(Unit)
|
||||
} catch (e: Exception) {
|
||||
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