mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 16:19:33 +01:00
Handle rate limits when rotating recovery key.
This commit is contained in:
@@ -142,6 +142,7 @@ import org.whispersystems.signalservice.api.ApplicationErrorAction
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.StatusCodeErrorAction
|
||||
import org.whispersystems.signalservice.api.archive.ArchiveGetMediaItemsResponse
|
||||
import org.whispersystems.signalservice.api.archive.ArchiveKeyRotationLimitResponse
|
||||
import org.whispersystems.signalservice.api.archive.ArchiveMediaRequest
|
||||
import org.whispersystems.signalservice.api.archive.ArchiveMediaResponse
|
||||
import org.whispersystems.signalservice.api.archive.ArchiveServiceAccess
|
||||
@@ -2063,6 +2064,10 @@ object BackupRepository {
|
||||
.then { SignalNetwork.archive.getSvrBAuthorization(SignalStore.account.requireAci(), it.messageBackupAccess) }
|
||||
}
|
||||
|
||||
fun getKeyRotationLimit(): NetworkResult<ArchiveKeyRotationLimitResponse> {
|
||||
return SignalNetwork.archive.getKeyRotationLimit()
|
||||
}
|
||||
|
||||
/**
|
||||
* During normal operation, ensures that the backupId has been reserved and that your public key has been set,
|
||||
* while also returning an archive access data. Should be the basis of all backup operations.
|
||||
|
||||
@@ -70,7 +70,8 @@ sealed interface MessageBackupsKeyRecordMode {
|
||||
data class CreateNewKey(
|
||||
val onCreateNewKeyClick: () -> Unit,
|
||||
val onTurnOffAndDownloadClick: () -> Unit,
|
||||
val isOptimizedStorageEnabled: Boolean
|
||||
val isOptimizedStorageEnabled: Boolean,
|
||||
val canRotateKey: Boolean
|
||||
) : MessageBackupsKeyRecordMode
|
||||
}
|
||||
|
||||
@@ -263,10 +264,17 @@ private fun CreateNewKeyButton(
|
||||
mode: MessageBackupsKeyRecordMode.CreateNewKey
|
||||
) {
|
||||
var displayBottomSheet by remember { mutableStateOf(false) }
|
||||
var displayDialog by remember { mutableStateOf(false) }
|
||||
var displayDownloadMediaDialog by remember { mutableStateOf(false) }
|
||||
var displayKeyLimitDialog by remember { mutableStateOf(false) }
|
||||
|
||||
TextButton(
|
||||
onClick = { displayBottomSheet = true },
|
||||
onClick = {
|
||||
if (!mode.canRotateKey) {
|
||||
displayKeyLimitDialog = true
|
||||
} else {
|
||||
displayBottomSheet = true
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(bottom = 24.dp)
|
||||
.horizontalGutters()
|
||||
@@ -276,10 +284,16 @@ private fun CreateNewKeyButton(
|
||||
Text(text = stringResource(R.string.MessageBackupsKeyRecordScreen__create_new_key))
|
||||
}
|
||||
|
||||
if (displayDialog) {
|
||||
if (displayKeyLimitDialog) {
|
||||
KeyLimitExceededDialog(
|
||||
onClick = { displayKeyLimitDialog = false }
|
||||
)
|
||||
}
|
||||
|
||||
if (displayDownloadMediaDialog) {
|
||||
DownloadMediaDialog(
|
||||
onTurnOffAndDownloadClick = mode.onTurnOffAndDownloadClick,
|
||||
onCancelClick = { displayDialog = false }
|
||||
onCancelClick = { displayDownloadMediaDialog = false }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -291,7 +305,7 @@ private fun CreateNewKeyButton(
|
||||
CreateNewBackupKeySheetContent(
|
||||
onContinueClick = {
|
||||
if (mode.isOptimizedStorageEnabled) {
|
||||
displayDialog = true
|
||||
displayDownloadMediaDialog = true
|
||||
} else {
|
||||
mode.onCreateNewKeyClick()
|
||||
}
|
||||
@@ -448,6 +462,19 @@ private fun DownloadMediaDialog(
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun KeyLimitExceededDialog(
|
||||
onClick: () -> Unit = {}
|
||||
) {
|
||||
Dialogs.SimpleAlertDialog(
|
||||
title = stringResource(R.string.MessageBackupsKeyRecordScreen__limit_exceeded_title),
|
||||
body = stringResource(R.string.MessageBackupsKeyRecordScreen__limit_exceeded_body),
|
||||
confirm = stringResource(R.string.MessageBackupsKeyRecordScreen__ok),
|
||||
onConfirm = {},
|
||||
onDismiss = onClick
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun saveKeyToCredentialManager(
|
||||
@UiContext activityContext: Context,
|
||||
backupKey: String
|
||||
@@ -470,7 +497,8 @@ private fun MessageBackupsKeyRecordScreenPreview() {
|
||||
mode = MessageBackupsKeyRecordMode.CreateNewKey(
|
||||
onCreateNewKeyClick = {},
|
||||
onTurnOffAndDownloadClick = {},
|
||||
isOptimizedStorageEnabled = true
|
||||
isOptimizedStorageEnabled = true,
|
||||
canRotateKey = true
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -507,3 +535,11 @@ private fun DownloadMediaDialogPreview() {
|
||||
DownloadMediaDialog()
|
||||
}
|
||||
}
|
||||
|
||||
@DayNightPreviews
|
||||
@Composable
|
||||
private fun KeyLimitExceededDialogPreview() {
|
||||
Previews.Preview {
|
||||
KeyLimitExceededDialog()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user