mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-09-13 12:07:57 +01:00
Add nopni capability detection when linking a device.
This commit is contained in:
committed by
Cody Henthorne
parent
f141bd536b
commit
771cae8a9a
@@ -84,6 +84,16 @@ fun LinkDeviceQrScanScreen(
|
||||
onDismiss = onQrCodeDismissed
|
||||
)
|
||||
}
|
||||
|
||||
LinkDeviceSettingsState.QrCodeState.OUTDATED_DEVICE -> {
|
||||
Dialogs.SimpleAlertDialog(
|
||||
title = stringResource(id = R.string.AddLinkDeviceFragment__linking_device_failed),
|
||||
body = stringResource(id = R.string.AddLinkDeviceFragment__the_device_you_are_trying_to_link_is_out_of_date),
|
||||
confirm = stringResource(id = android.R.string.ok),
|
||||
onConfirm = { },
|
||||
onDismiss = onQrCodeDismissed
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(linkDeviceResult) {
|
||||
|
||||
@@ -51,7 +51,7 @@ data class LinkDeviceSettingsState(
|
||||
}
|
||||
|
||||
enum class QrCodeState {
|
||||
NONE, VALID_WITH_SYNC, VALID_WITHOUT_SYNC, INVALID
|
||||
NONE, VALID_WITH_SYNC, VALID_WITHOUT_SYNC, INVALID, OUTDATED_DEVICE
|
||||
}
|
||||
|
||||
enum class SyncFailType {
|
||||
|
||||
@@ -171,9 +171,15 @@ class LinkDeviceViewModel : ViewModel() {
|
||||
|
||||
val uri = Uri.parse(url)
|
||||
if (LinkDeviceRepository.isValidQr(uri)) {
|
||||
val capabilities = uri.getCapabilities()
|
||||
val qrCodeState = when {
|
||||
Capability.Numberless !in capabilities && SignalStore.account.pni == null -> QrCodeState.OUTDATED_DEVICE
|
||||
Capability.LinkAndSync in capabilities -> QrCodeState.VALID_WITH_SYNC
|
||||
else -> QrCodeState.VALID_WITHOUT_SYNC
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
qrCodeState = if (uri.supportsLinkAndSync()) QrCodeState.VALID_WITH_SYNC else QrCodeState.VALID_WITHOUT_SYNC,
|
||||
qrCodeState = qrCodeState,
|
||||
linkUri = uri
|
||||
)
|
||||
}
|
||||
@@ -215,7 +221,7 @@ class LinkDeviceViewModel : ViewModel() {
|
||||
Log.i(TAG, "Adding device with sync.")
|
||||
addDeviceWithSync(linkUri)
|
||||
} else {
|
||||
Log.i(TAG, "Adding device without sync. (uri: ${linkUri.supportsLinkAndSync()})")
|
||||
Log.i(TAG, "Adding device without sync. (backup5: ${Capability.LinkAndSync in linkUri.getCapabilities()})")
|
||||
addDeviceWithoutSync(linkUri)
|
||||
}
|
||||
}
|
||||
@@ -413,9 +419,17 @@ class LinkDeviceViewModel : ViewModel() {
|
||||
LinkedDeviceInactiveCheckJob.enqueue()
|
||||
}
|
||||
|
||||
private fun Uri.supportsLinkAndSync(): Boolean {
|
||||
val capabilities = this.getQueryParameter("capabilities")?.split(",")?.toSet() ?: emptySet()
|
||||
return "backup5" in capabilities
|
||||
private fun Uri.getCapabilities(): Set<Capability> {
|
||||
return this.getQueryParameter("capabilities")
|
||||
?.split(",")
|
||||
?.mapNotNull { value -> Capability.entries.firstOrNull { it.value == value } }
|
||||
?.toSet()
|
||||
?: emptySet()
|
||||
}
|
||||
|
||||
private enum class Capability(val value: String) {
|
||||
LinkAndSync("backup5"),
|
||||
Numberless("nopni")
|
||||
}
|
||||
|
||||
fun onSyncErrorIgnored() = viewModelScope.launch(Dispatchers.IO) {
|
||||
|
||||
@@ -1192,6 +1192,8 @@
|
||||
<string name="AddLinkDeviceFragment__this_qr_code_not_valid">This QR code is not valid. Please make sure you are scanning the QR code that is displayed on the device you want to link.</string>
|
||||
<!-- Button in dialog to retry linking a device with a qr code -->
|
||||
<string name="AddLinkDeviceFragment__retry">Retry</string>
|
||||
<!-- Text shown in a dialog when the device being linked is too out-of-date to be linked to this account -->
|
||||
<string name="AddLinkDeviceFragment__the_device_you_are_trying_to_link_is_out_of_date">The device you\'re trying to link is out of date. Please upgrade and try again.</string>
|
||||
|
||||
<!-- LinkDeviceSyncBottomSheet -->
|
||||
<!-- Option in bottom sheet to transfer message history -->
|
||||
|
||||
Reference in New Issue
Block a user