Skip to content

Commit a5c2113

Browse files
cody-signalgreyson-signal
authored andcommitted
Add backup delete all to internal settings.
1 parent 1af8b3a commit a5c2113

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

app/src/main/java/org/thoughtcrime/securesms/backup/v2/BackupRepository.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,13 @@ object BackupRepository {
12151215
.also { Log.i(TAG, "deleteAbandonedMediaObjectsResult: $it") }
12161216
}
12171217

1218+
fun deleteBackup(): NetworkResult<Unit> {
1219+
return initBackupAndFetchAuth()
1220+
.then { credential ->
1221+
SignalNetwork.archive.deleteBackup(SignalStore.account.requireAci(), credential.messageBackupAccess)
1222+
}
1223+
}
1224+
12181225
fun debugDeleteAllArchivedMedia(): NetworkResult<Unit> {
12191226
return debugGetArchivedMediaState()
12201227
.then { archivedMedia ->

app/src/main/java/org/thoughtcrime/securesms/components/settings/app/internal/backup/InternalBackupPlaygroundFragment.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ import androidx.compose.ui.text.input.KeyboardType
6464
import androidx.compose.ui.unit.dp
6565
import androidx.compose.ui.window.DialogProperties
6666
import androidx.fragment.app.viewModels
67+
import androidx.lifecycle.lifecycleScope
6768
import androidx.navigation.fragment.findNavController
6869
import com.google.android.material.dialog.MaterialAlertDialogBuilder
70+
import kotlinx.coroutines.Dispatchers
71+
import kotlinx.coroutines.launch
72+
import kotlinx.coroutines.withContext
6973
import org.signal.core.ui.Dividers
7074
import org.signal.core.ui.Previews
7175
import org.signal.core.ui.Rows
@@ -222,6 +226,21 @@ class InternalBackupPlaygroundFragment : ComposeFragment() {
222226
.setMessage("After you choose a file to import, this will delete all of your chats, then restore them from the file! Only do this on a test device!")
223227
.setPositiveButton("Wipe and restore") { _, _ -> viewModel.import(SignalStore.settings.signalBackupDirectory!!) }
224228
.show()
229+
},
230+
onDeleteRemoteBackup = {
231+
MaterialAlertDialogBuilder(context)
232+
.setTitle("Are you sure?")
233+
.setMessage("This will delete all of your remote backup data?")
234+
.setPositiveButton("Delete remote data") { _, _ ->
235+
lifecycleScope.launch {
236+
val success = viewModel.deleteRemoteBackupData()
237+
withContext(Dispatchers.Main) {
238+
Toast.makeText(requireContext(), if (success) "Deleted!" else "Failed!", Toast.LENGTH_SHORT).show()
239+
}
240+
}
241+
}
242+
.setNegativeButton("Cancel", null)
243+
.show()
225244
}
226245
)
227246
},
@@ -317,7 +336,8 @@ fun Screen(
317336
onSavePlaintextBackupToDiskClicked: () -> Unit = {},
318337
onImportEncryptedBackupFromDiskClicked: () -> Unit = {},
319338
onImportEncryptedBackupFromDiskDismissed: () -> Unit = {},
320-
onImportEncryptedBackupFromDiskConfirmed: (aci: String, backupKey: String) -> Unit = { _, _ -> }
339+
onImportEncryptedBackupFromDiskConfirmed: (aci: String, backupKey: String) -> Unit = { _, _ -> },
340+
onDeleteRemoteBackup: () -> Unit = {}
321341
) {
322342
val context = LocalContext.current
323343
val scrollState = rememberScrollState()
@@ -492,6 +512,12 @@ fun Screen(
492512
onClick = onImportNewStyleLocalBackupClicked
493513
)
494514

515+
Rows.TextRow(
516+
text = "Delete all backup data on server",
517+
label = "Erases all content on the server.",
518+
onClick = onDeleteRemoteBackup
519+
)
520+
495521
Dividers.Default()
496522

497523
Spacer(modifier = Modifier.height(8.dp))

app/src/main/java/org/thoughtcrime/securesms/components/settings/app/internal/backup/InternalBackupPlaygroundViewModel.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable
1818
import io.reactivex.rxjava3.kotlin.plusAssign
1919
import io.reactivex.rxjava3.kotlin.subscribeBy
2020
import io.reactivex.rxjava3.schedulers.Schedulers
21+
import kotlinx.coroutines.Dispatchers
22+
import kotlinx.coroutines.withContext
2123
import org.signal.core.util.Hex
2224
import org.signal.core.util.bytes
2325
import org.signal.core.util.concurrent.SignalExecutors
@@ -155,6 +157,7 @@ class InternalBackupPlaygroundViewModel : ViewModel() {
155157
Log.w(TAG, "Validation failed! Details: ${result.messageDetails}", result.exception)
156158
"Validation failed :( Check the logs for details."
157159
}
160+
158161
is ArchiveValidator.ValidationResult.RecipientDuplicateE164Error -> {
159162
Log.w(TAG, "Validation failed with a duplicate recipient! Details: ${result.details}", result.exception)
160163
"Validation failed :( Check the logs for details."
@@ -532,6 +535,29 @@ class InternalBackupPlaygroundViewModel : ViewModel() {
532535
)
533536
}
534537

538+
suspend fun deleteRemoteBackupData(): Boolean = withContext(Dispatchers.IO) {
539+
when (val result = BackupRepository.debugDeleteAllArchivedMedia()) {
540+
is NetworkResult.Success -> Log.i(TAG, "Remote data deleted")
541+
else -> {
542+
Log.w(TAG, "Unable to delete media", result.getCause())
543+
return@withContext false
544+
}
545+
}
546+
547+
when (val result = BackupRepository.deleteBackup()) {
548+
is NetworkResult.Success -> {
549+
SignalStore.backup.backupsInitialized = false
550+
SignalStore.backup.messageCredentials.clearAll()
551+
SignalStore.backup.mediaCredentials.clearAll()
552+
SignalStore.backup.cachedMediaCdnPath = null
553+
return@withContext true
554+
}
555+
else -> Log.w(TAG, "Unable to delete remote data", result.getCause())
556+
}
557+
558+
return@withContext false
559+
}
560+
535561
override fun onCleared() {
536562
disposables.clear()
537563
}

0 commit comments

Comments
 (0)