Add support for downgrading backup.
This commit is contained in:
parent
e6fb01a67b
commit
b1a4e889bc
4 changed files with 25 additions and 10 deletions
|
@ -243,6 +243,8 @@ class MessageBackupsFlowFragment : ComposeFragment(), InAppPaymentCheckoutDelega
|
|||
}
|
||||
|
||||
override fun onSubscriptionCancelled(inAppPaymentType: InAppPaymentType) {
|
||||
viewModel.onCancellationComplete()
|
||||
|
||||
if (!findNavController().popBackStack()) {
|
||||
requireActivity().finishAfterTransition()
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ class MessageBackupsFlowViewModel : ViewModel() {
|
|||
)
|
||||
|
||||
private val internalPinState = mutableStateOf("")
|
||||
private var isDowngrading = false
|
||||
|
||||
val stateFlow: StateFlow<MessageBackupsFlowState> = internalStateFlow
|
||||
val pinState: State<String> = internalPinState
|
||||
|
@ -129,6 +130,15 @@ class MessageBackupsFlowViewModel : ViewModel() {
|
|||
internalStateFlow.update { it.copy(selectedMessageBackupTier = messageBackupTier) }
|
||||
}
|
||||
|
||||
fun onCancellationComplete() {
|
||||
if (isDowngrading) {
|
||||
SignalStore.backup.areBackupsEnabled = true
|
||||
SignalStore.backup.backupTier = MessageBackupTier.FREE
|
||||
|
||||
// TODO [message-backups] -- Trigger backup now?
|
||||
}
|
||||
}
|
||||
|
||||
private fun validatePinAndUpdateState(pin: String): MessageBackupsScreen {
|
||||
val pinHash = SignalStore.svr.localPinHash
|
||||
|
||||
|
@ -141,14 +151,18 @@ class MessageBackupsFlowViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
private fun validateTypeAndUpdateState(tier: MessageBackupTier): MessageBackupsScreen {
|
||||
// TODO [message-backups] - Does anything need to be kicked off?
|
||||
|
||||
return when (tier) {
|
||||
MessageBackupTier.FREE -> {
|
||||
SignalStore.backup.areBackupsEnabled = true
|
||||
SignalStore.backup.backupTier = MessageBackupTier.FREE
|
||||
if (SignalStore.backup.backupTier == MessageBackupTier.PAID) {
|
||||
isDowngrading = true
|
||||
MessageBackupsScreen.PROCESS_CANCELLATION
|
||||
} else {
|
||||
SignalStore.backup.areBackupsEnabled = true
|
||||
SignalStore.backup.backupTier = MessageBackupTier.FREE
|
||||
|
||||
MessageBackupsScreen.COMPLETED
|
||||
// TODO [message-backups] -- Trigger backup now?
|
||||
MessageBackupsScreen.COMPLETED
|
||||
}
|
||||
}
|
||||
MessageBackupTier.PAID -> MessageBackupsScreen.CHECKOUT_SHEET
|
||||
}
|
||||
|
|
|
@ -148,14 +148,14 @@ fun MessageBackupsTypeSelectionScreen(
|
|||
}
|
||||
}
|
||||
|
||||
val hasSelectedBackupTier = currentBackupTier != null
|
||||
val hasCurrentBackupTier = currentBackupTier != null
|
||||
|
||||
Buttons.LargePrimary(
|
||||
onClick = onNextClicked,
|
||||
enabled = selectedBackupTier != null,
|
||||
enabled = selectedBackupTier != currentBackupTier && hasCurrentBackupTier,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = if (hasSelectedBackupTier) 10.dp else 16.dp)
|
||||
.padding(vertical = if (hasCurrentBackupTier) 10.dp else 16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(
|
||||
|
@ -168,7 +168,7 @@ fun MessageBackupsTypeSelectionScreen(
|
|||
)
|
||||
}
|
||||
|
||||
if (hasSelectedBackupTier) {
|
||||
if (hasCurrentBackupTier) {
|
||||
TextButton(
|
||||
onClick = onCancelSubscriptionClicked,
|
||||
modifier = Modifier
|
||||
|
|
|
@ -466,7 +466,6 @@ class InAppPaymentValues internal constructor(store: KeyValueStore) : SignalStor
|
|||
} else {
|
||||
markBackupSubscriptionpManuallyCancelled()
|
||||
|
||||
// TODO [message-backups] -- Handle downgrades?
|
||||
SignalStore.backup.areBackupsEnabled = false
|
||||
SignalStore.backup.backupTier = null
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue