Add display of last backup time to restore flow.

This commit is contained in:
Clark
2024-06-11 10:10:45 -04:00
committed by Greyson Parrelli
parent 16773c9b17
commit 6adddf4a0c
7 changed files with 53 additions and 17 deletions

View File

@@ -41,6 +41,7 @@ import org.thoughtcrime.securesms.groups.GroupId
import org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.util.toMillis
import org.whispersystems.signalservice.api.NetworkResult
import org.whispersystems.signalservice.api.StatusCodeErrorAction
import org.whispersystems.signalservice.api.archive.ArchiveGetMediaItemsResponse
@@ -62,6 +63,7 @@ import java.io.File
import java.io.InputStream
import java.io.OutputStream
import java.lang.Exception
import java.time.ZonedDateTime
import kotlin.time.Duration.Companion.milliseconds
object BackupRepository {
@@ -355,7 +357,7 @@ object BackupRepository {
} is NetworkResult.Success
}
fun checkForBackupFile(): Boolean {
fun getBackupFileLastModified(): NetworkResult<ZonedDateTime?> {
val api = AppDependencies.signalServiceAccountManager.archiveApi
val backupKey = SignalStore.svr().getOrCreateMasterKey().deriveBackupKey()
@@ -368,9 +370,9 @@ object BackupRepository {
val (cdnCredentials, info) = pair
val messageReceiver = AppDependencies.signalServiceMessageReceiver
NetworkResult.fromFetch {
messageReceiver.checkBackupExistence(info.cdn!!, cdnCredentials, "backups/${info.backupDir}/${info.backupName}")
messageReceiver.getCdnLastModifiedTime(info.cdn!!, cdnCredentials, "backups/${info.backupDir}/${info.backupName}")
}
} is NetworkResult.Success
}
}
/**
@@ -605,7 +607,10 @@ object BackupRepository {
fun restoreBackupTier(): MessageBackupTier? {
// TODO: more complete error handling
try {
checkForBackupFile()
val lastModified = getBackupFileLastModified().successOrThrow()
if (lastModified != null) {
SignalStore.backup().lastBackupTime = lastModified.toMillis()
}
} catch (e: Exception) {
Log.i(TAG, "Could not check for backup file.", e)
SignalStore.backup().backupTier = null

View File

@@ -32,7 +32,14 @@ import kotlin.time.Duration.Companion.seconds
class RemoteRestoreViewModel : ViewModel() {
val disposables = CompositeDisposable()
private val _state: MutableState<ScreenState> = mutableStateOf(ScreenState(backupTier = SignalStore.backup().backupTier, importState = ImportState.NONE, restoreProgress = null))
private val _state: MutableState<ScreenState> = mutableStateOf(
ScreenState(
backupTier = SignalStore.backup().backupTier,
backupTime = SignalStore.backup().lastBackupTime,
importState = ImportState.NONE,
restoreProgress = null
)
)
val state: State<ScreenState> = _state
@@ -78,6 +85,7 @@ class RemoteRestoreViewModel : ViewModel() {
data class ScreenState(
val backupTier: MessageBackupTier?,
val backupTime: Long,
val importState: ImportState,
val restoreProgress: RestoreV2Event?
)

View File

@@ -143,7 +143,10 @@ class InternalBackupPlaygroundViewModel : ViewModel() {
_state.value = _state.value.copy(remoteBackupState = RemoteBackupState.Unknown)
disposables += Single
.fromCallable { BackupRepository.getRemoteBackupState() }
.fromCallable {
BackupRepository.restoreBackupTier()
BackupRepository.getRemoteBackupState()
}
.subscribeOn(Schedulers.io())
.subscribe { result ->
when {

View File

@@ -30,6 +30,7 @@ import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
@@ -63,7 +64,9 @@ import org.thoughtcrime.securesms.profiles.edit.CreateProfileActivity
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.registration.RegistrationUtil
import org.thoughtcrime.securesms.restore.transferorrestore.TransferOrRestoreMoreOptionsDialog
import org.thoughtcrime.securesms.util.DateUtils
import org.thoughtcrime.securesms.util.Util
import java.util.Locale
class RemoteRestoreActivity : BaseActivity() {
companion object {
@@ -93,6 +96,7 @@ class RemoteRestoreActivity : BaseActivity() {
TransferOrRestoreMoreOptionsDialog.show(fragmentManager = supportFragmentManager, skipOnly = false)
},
state.backupTier,
state.backupTime,
state.backupTier != MessageBackupTier.PAID
)
if (state.importState == RemoteRestoreViewModel.ImportState.RESTORED) {
@@ -238,6 +242,7 @@ class RemoteRestoreActivity : BaseActivity() {
onCancelClick = {},
onMoreOptionsClick = {},
MessageBackupTier.PAID,
System.currentTimeMillis(),
true
)
}
@@ -250,6 +255,7 @@ class RemoteRestoreActivity : BaseActivity() {
onCancelClick: () -> Unit,
onMoreOptionsClick: () -> Unit,
tier: MessageBackupTier?,
lastBackupTime: Long,
cancelable: Boolean
) {
Column(
@@ -264,7 +270,14 @@ class RemoteRestoreActivity : BaseActivity() {
)
val yourLastBackupText = buildAnnotatedString {
append("Your last backup was made on March 5, 2024 at 9:00am.") // TODO [message-backups] Finalized copy.
append(
stringResource(
id = R.string.RemoteRestoreActivity__backup_created_at,
DateUtils.formatDateWithoutDayOfWeek(Locale.getDefault(), lastBackupTime),
DateUtils.getOnlyTimeString(LocalContext.current, lastBackupTime)
)
)
append(" ")
if (tier != MessageBackupTier.PAID) {
withStyle(SpanStyle(fontWeight = FontWeight.SemiBold)) {