Add subscription states to the remote backups settings.

This commit is contained in:
Alex Hart
2024-10-21 13:22:45 -03:00
committed by Greyson Parrelli
parent a66c7058b1
commit b519bf6772
12 changed files with 522 additions and 227 deletions

View File

@@ -119,16 +119,20 @@ object BackupRepository {
}
}
/**
* If the user is on a paid tier, this method will unsubscribe them from that tier.
* It will then disable backups.
*
* Returns true if we were successful, false otherwise.
*/
@WorkerThread
fun turnOffAndDeleteBackup(): Boolean {
fun turnOffAndDisableBackups(): Boolean {
return try {
Log.d(TAG, "Attempting to disable backups.")
getBackupTier().runIfSuccessful { tier ->
if (tier == MessageBackupTier.PAID) {
Log.d(TAG, "User is currently on a paid tier. Canceling.")
RecurringInAppPaymentRepository.cancelActiveSubscriptionSync(InAppPaymentSubscriberRecord.Type.BACKUP)
Log.d(TAG, "Successfully canceled paid tier.")
}
if (SignalStore.backup.backupTier == MessageBackupTier.PAID) {
Log.d(TAG, "User is currently on a paid tier. Canceling.")
RecurringInAppPaymentRepository.cancelActiveSubscriptionSync(InAppPaymentSubscriberRecord.Type.BACKUP)
Log.d(TAG, "Successfully canceled paid tier.")
}
Log.d(TAG, "Disabling backups.")
@@ -636,14 +640,11 @@ object BackupRepository {
}
/**
* If backups are initialized, this method will query the server for the current backup level.
* If backups are not initialized, this method will return either the stored tier or a 404 result.
* If backups are enabled, sync with the network. Otherwise, return a 404.
*/
fun getBackupTier(): NetworkResult<MessageBackupTier> {
return if (SignalStore.backup.backupsInitialized) {
return if (SignalStore.backup.areBackupsEnabled) {
getBackupTier(Recipient.self().requireAci())
} else if (SignalStore.backup.backupTier != null) {
NetworkResult.Success(SignalStore.backup.backupTier!!)
} else {
NetworkResult.StatusCodeError(NonSuccessfulResponseCodeException(404))
}

View File

@@ -118,11 +118,7 @@ class MessageBackupsFlowFragment : ComposeFragment(), InAppPaymentCheckoutDelega
currentBackupTier = state.currentMessageBackupTier,
selectedBackupTier = state.selectedMessageBackupTier,
availableBackupTypes = state.availableBackupTypes.filter { it.tier == MessageBackupTier.FREE || state.hasBackupSubscriberAvailable },
onMessageBackupsTierSelected = { tier ->
val type = state.availableBackupTypes.first { it.tier == tier }
viewModel.onMessageBackupTierUpdated(tier)
},
onMessageBackupsTierSelected = viewModel::onMessageBackupTierUpdated,
onNavigationClick = viewModel::goToPreviousStage,
onReadMoreClicked = {},
onNextClicked = viewModel::goToNextStage

View File

@@ -97,6 +97,13 @@ class MessageBackupsFlowViewModel(
try {
Log.d(TAG, "Attempting to handle successful purchase.")
internalStateFlow.update {
it.copy(
stage = MessageBackupsStage.PROCESS_PAYMENT
)
}
handleSuccess(result, id)
internalStateFlow.update {