Check remaining attachment size before launching service.

This commit is contained in:
Michelle Tang
2025-08-22 11:30:40 -04:00
parent 9a9661149b
commit 8723fd9a24
2 changed files with 29 additions and 6 deletions

View File

@@ -256,6 +256,16 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
}
}
}
launch {
mainNavigationViewModel.backupStatus.collect { remainingRestoreSize ->
if (SignalStore.backup.restoreState == RestoreState.RESTORING_MEDIA && remainingRestoreSize != 0L) {
Log.i(TAG, "Still restoring media, launching a service. Remaining restoration size: $remainingRestoreSize")
BackupMediaRestoreService.resetTimeout()
BackupMediaRestoreService.start(this@MainActivity, resources.getString(R.string.BackupStatus__restoring_media))
}
}
}
}
val callback = object : OnBackPressedCallback(toolbarViewModel.state.value.mode == MainToolbarMode.ACTION_MODE) {
@@ -272,12 +282,6 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
}
}
if (SignalStore.backup.restoreState == RestoreState.RESTORING_MEDIA) {
Log.i(TAG, "Still restoring media, launching a service.")
BackupMediaRestoreService.resetTimeout()
BackupMediaRestoreService.start(this, resources.getString(R.string.BackupStatus__restoring_media))
}
onBackPressedDispatcher.addCallback(this, callback)
shareDataTimestampViewModel.setTimestampFromActivityCreation(savedInstanceState, intent)

View File

@@ -21,7 +21,9 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.reactive.asFlow
import kotlinx.coroutines.rx3.asObservable
import org.thoughtcrime.securesms.backup.RestoreState
import org.thoughtcrime.securesms.components.settings.app.notifications.profiles.NotificationProfilesRepository
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.megaphone.Megaphone
@@ -62,6 +64,9 @@ class MainNavigationViewModel(
private val internalMainNavigationState = MutableStateFlow(MainNavigationState(currentListLocation = initialListLocation))
val mainNavigationState: StateFlow<MainNavigationState> = internalMainNavigationState
private val internalBackupStatus = MutableStateFlow(0L)
val backupStatus: StateFlow<Long> = internalBackupStatus
/**
* This is Rx because these are still accessed from Java.
*/
@@ -84,6 +89,8 @@ class MainNavigationViewModel(
performStoreUpdate(MainNavigationRepository.getHasFailedOutgoingStories()) { hasFailedStories, state ->
state.copy(storyFailure = hasFailedStories)
}
getRemainingRestoreAttachmentSize()
}
/**
@@ -212,6 +219,18 @@ class MainNavigationViewModel(
}
}
private fun getRemainingRestoreAttachmentSize() {
viewModelScope.launch {
internalBackupStatus.update {
if (SignalStore.backup.restoreState == RestoreState.RESTORING_MEDIA) {
SignalDatabase.attachments.getRemainingRestorableAttachmentSize()
} else {
0L
}
}
}
}
private fun <T : Any> performStoreUpdate(flow: Flow<T>, fn: (T, MainNavigationState) -> MainNavigationState) {
viewModelScope.launch {
flow.collectLatest { item ->