Add several state presentation fixes in the delete / enable cycle.

This commit is contained in:
Alex Hart
2025-07-28 15:31:18 -03:00
committed by GitHub
parent d3030e143b
commit ab458a5bb8
4 changed files with 34 additions and 14 deletions

View File

@@ -171,7 +171,7 @@ private fun BackupsSettingsContent(
is BackupState.ActiveFree, is BackupState.ActivePaid, is BackupState.Canceled -> {
ActiveBackupsRow(
backupState = backupsSettingsState.backupState as BackupState.WithTypeAndRenewalTime,
backupState = backupsSettingsState.backupState,
onBackupsRowClick = onBackupsRowClick,
lastBackupAt = backupsSettingsState.lastBackupAt
)
@@ -188,7 +188,10 @@ private fun BackupsSettingsContent(
}
BackupState.Error -> {
WaitingForNetworkRow()
WaitingForNetworkRow(
onBackupsRowClick = onBackupsRowClick
)
OtherWaysToBackUpHeading()
}
@@ -283,10 +286,13 @@ private fun NeverEnabledBackupsRow(
}
@Composable
private fun WaitingForNetworkRow() {
private fun WaitingForNetworkRow(onBackupsRowClick: () -> Unit = {}) {
Rows.TextRow(
text = {
Text(text = stringResource(R.string.RemoteBackupsSettingsFragment__waiting_for_network))
Column {
Text(text = stringResource(R.string.RemoteBackupsSettingsFragment__waiting_for_network))
ViewSettingsButton(onBackupsRowClick)
}
},
icon = {
CircularProgressIndicator()
@@ -307,6 +313,7 @@ private fun InactiveBackupsRow(
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
ViewSettingsButton(onBackupsRowClick)
}
},
icon = {
@@ -315,8 +322,7 @@ private fun InactiveBackupsRow(
contentDescription = stringResource(R.string.preferences_chats__backups),
tint = MaterialTheme.colorScheme.onSurface
)
},
onClick = onBackupsRowClick
}
)
}
@@ -347,9 +353,9 @@ private fun NotFoundBackupRow(
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
ViewSettingsButton(onBackupsRowClick)
}
},
onClick = onBackupsRowClick
}
)
}

View File

@@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.backup.ArchiveUploadProgress
import org.thoughtcrime.securesms.backup.DeletionState
import org.thoughtcrime.securesms.backup.v2.BackupFrequency
import org.thoughtcrime.securesms.backup.v2.BackupRepository
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
import org.thoughtcrime.securesms.backup.v2.ui.status.BackupStatusData
import org.thoughtcrime.securesms.banner.banners.MediaRestoreProgressBanner
import org.thoughtcrime.securesms.components.settings.app.backups.BackupStateRepository
@@ -238,7 +239,7 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
private fun refreshBackupMediaSizeState() {
_state.update {
it.copy(
backupMediaSize = SignalDatabase.attachments.getEstimatedArchiveMediaSize(),
backupMediaSize = getBackupMediaSize(),
backupMediaDetails = if (RemoteConfig.internalUser || Environment.IS_STAGING) {
RemoteBackupsSettingsState.BackupMediaDetails(
awaitingRestore = SignalDatabase.attachments.getRemainingRestorableAttachmentSize().bytes,
@@ -287,7 +288,7 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
backupsEnabled = SignalStore.backup.areBackupsEnabled,
lastBackupTimestamp = SignalStore.backup.lastBackupTime,
canBackupMessagesJobRun = BackupMessagesConstraint.isMet(AppDependencies.application),
backupMediaSize = SignalDatabase.attachments.getEstimatedArchiveMediaSize(),
backupMediaSize = getBackupMediaSize(),
backupsFrequency = SignalStore.backup.backupFrequency,
canBackUpUsingCellular = SignalStore.backup.backupWithCellular,
canRestoreUsingCellular = SignalStore.backup.restoreWithCellular,
@@ -301,4 +302,12 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
it.copy(backupState = state)
}
}
private fun getBackupMediaSize(): Long {
return if (SignalStore.backup.backupTier == MessageBackupTier.PAID && SignalStore.backup.hasBackupBeenUploaded) {
SignalDatabase.attachments.getEstimatedArchiveMediaSize()
} else {
0L
}
}
}

View File

@@ -630,6 +630,12 @@ class AttachmentTable(
.readToSingleLong()
}
private fun getMessageDoesNotExpireWithinTimeoutClause(tablePrefix: String = MessageTable.TABLE_NAME): String {
val messageHasExpiration = "$tablePrefix.${MessageTable.EXPIRES_IN} > 0"
val messageExpiresInOneDayAfterViewing = "$messageHasExpiration AND $tablePrefix.${MessageTable.EXPIRES_IN} < ${1.days.inWholeMilliseconds}"
return "NOT $messageExpiresInOneDayAfterViewing"
}
/**
* Finds all of the attachmentIds of attachments that need to be uploaded to the archive cdn.
*/
@@ -2467,8 +2473,6 @@ class AttachmentTable(
}
fun getEstimatedArchiveMediaSize(): Long {
val expirationCutoff = ChatItemArchiveExporter.EXPIRATION_CUTOFF.inWholeMilliseconds
val estimatedThumbnailCount = readableDatabase
.select("COUNT(*)")
.from(
@@ -2483,7 +2487,7 @@ class AttachmentTable(
$TRANSFER_STATE = $TRANSFER_PROGRESS_DONE AND
$ARCHIVE_TRANSFER_STATE != ${ArchiveTransferState.PERMANENT_FAILURE.value} AND
($CONTENT_TYPE LIKE 'image/%' OR $CONTENT_TYPE LIKE 'video/%') AND
(m.${MessageTable.EXPIRES_IN} = 0 OR (m.${MessageTable.EXPIRES_IN} > $expirationCutoff AND (m.${MessageTable.EXPIRE_STARTED} + m.${MessageTable.EXPIRES_IN} + $expirationCutoff < ${System.currentTimeMillis()})))
${getMessageDoesNotExpireWithinTimeoutClause(tablePrefix = "m")}
)
"""
)
@@ -2503,7 +2507,7 @@ class AttachmentTable(
$REMOTE_KEY NOT NULL AND
$TRANSFER_STATE = $TRANSFER_PROGRESS_DONE AND
$ARCHIVE_TRANSFER_STATE != ${ArchiveTransferState.PERMANENT_FAILURE.value} AND
(m.${MessageTable.EXPIRES_IN} = 0 OR (m.${MessageTable.EXPIRES_IN} > $expirationCutoff AND (m.${MessageTable.EXPIRE_STARTED} + m.${MessageTable.EXPIRES_IN} + $expirationCutoff < ${System.currentTimeMillis()})))
${getMessageDoesNotExpireWithinTimeoutClause(tablePrefix = "m")}
)
"""
)

View File

@@ -323,6 +323,7 @@ class BackupValues(store: KeyValueStore) : SignalStoreValues(store) {
store
.beginWrite()
.putLong(KEY_NEXT_BACKUP_TIME, -1)
.putLong(KEY_LAST_BACKUP_TIME, -1)
.putBoolean(KEY_BACKUPS_INITIALIZED, false)
.putBoolean(KEY_BACKUP_UPLOADED, false)
.putLong(KEY_LAST_VERIFY_KEY_TIME, -1)