Update some BackupValues stuff.

This commit is contained in:
Greyson Parrelli
2024-10-09 11:42:27 -04:00
parent 88ea258b45
commit 229a78305f
7 changed files with 71 additions and 34 deletions

View File

@@ -41,14 +41,14 @@ class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
private const val KEY_ARCHIVE_UPLOAD_STATE = "backup.archiveUploadState"
/**
* Specifies whether remote backups are enabled on this device.
*/
private const val KEY_BACKUPS_ENABLED = "backup.enabled"
private const val KEY_BACKUP_UPLOADED = "backup.backupUploaded"
private val cachedCdnCredentialsExpiresIn: Duration = 12.hours
}
override fun onFirstEverAppLaunch() = Unit
override fun getKeysToIncludeInBackup(): List<String> = emptyList()
private var cachedCdnCredentialsTimestamp: Long by longValue(KEY_CDN_READ_CREDENTIALS_TIMESTAMP, 0L)
private var cachedCdnCredentials: String? by stringValue(KEY_CDN_READ_CREDENTIALS, null)
var cachedBackupDirectory: String? by stringValue(KEY_CDN_BACKUP_DIRECTORY, null)
@@ -56,9 +56,6 @@ class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
var usedBackupMediaSpace: Long by longValue(KEY_BACKUP_USED_MEDIA_SPACE, 0L)
var lastBackupProtoSize: Long by longValue(KEY_BACKUP_LAST_PROTO_SIZE, 0L)
override fun onFirstEverAppLaunch() = Unit
override fun getKeysToIncludeInBackup(): List<String> = emptyList()
var restoreState: RestoreState by enumValue(KEY_RESTORE_STATE, RestoreState.NONE, RestoreState.serializer)
var optimizeStorage: Boolean by booleanValue(KEY_OPTIMIZE_STORAGE, false)
var backupWithCellular: Boolean by booleanValue(KEY_BACKUP_OVER_CELLULAR, false)
@@ -81,18 +78,25 @@ class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
@JvmName("backsUpMedia")
get() = backupTier == MessageBackupTier.PAID
var areBackupsEnabled: Boolean
get() {
return getBoolean(KEY_BACKUPS_ENABLED, false)
}
set(value) {
store
.beginWrite()
.putBoolean(KEY_BACKUPS_ENABLED, value)
.putLong(KEY_NEXT_BACKUP_TIME, -1)
.putBoolean(KEY_BACKUPS_INITIALIZED, false)
.apply()
}
/** True if the user has backups enabled, otherwise false. */
val areBackupsEnabled: Boolean
get() = backupTier != null
/** True if we believe we have successfully uploaded a backup, otherwise false. */
var hasBackupBeenUploaded: Boolean by booleanValue(KEY_BACKUP_UPLOADED, false)
/**
* Call when the user disables backups. Clears/resets all relevant fields.
*/
fun disableBackups() {
store
.beginWrite()
.putLong(KEY_NEXT_BACKUP_TIME, -1)
.putBoolean(KEY_BACKUPS_INITIALIZED, false)
.putBoolean(KEY_BACKUP_UPLOADED, false)
.apply()
backupTier = null
}
var backupsInitialized: Boolean by booleanValue(KEY_BACKUPS_INITIALIZED, false)

View File

@@ -471,8 +471,7 @@ class InAppPaymentValues internal constructor(store: KeyValueStore) : SignalStor
} else {
markBackupSubscriptionpManuallyCancelled()
SignalStore.backup.areBackupsEnabled = false
SignalStore.backup.backupTier = null
SignalStore.backup.disableBackups()
}
val subscriber = InAppPaymentsRepository.getSubscriber(subscriberType)
@@ -514,7 +513,6 @@ class InAppPaymentValues internal constructor(store: KeyValueStore) : SignalStor
} else {
clearBackupSubscriptionManuallyCancelled()
SignalStore.backup.areBackupsEnabled = true
SignalStore.backup.backupTier = MessageBackupTier.PAID
SignalStore.uiHints.markHasEverEnabledRemoteBackups()
}