mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 02:39:55 +01:00
Add "your media will be deleted today" mechanism based off last checkin time and media TTL.
This commit is contained in:
committed by
Greyson Parrelli
parent
f16827d9ec
commit
bae86d127f
@@ -101,6 +101,7 @@ import java.time.ZonedDateTime
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import kotlin.time.Duration.Companion.days
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import org.signal.libsignal.messagebackup.MessageBackupKey as LibSignalMessageBackupKey
|
||||
|
||||
@@ -237,6 +238,49 @@ object BackupRepository {
|
||||
return System.currentTimeMillis().milliseconds > SignalStore.backup.nextBackupFailureSheetSnoozeTime
|
||||
}
|
||||
|
||||
fun snoozeYourMediaWillBeDeletedTodaySheet() {
|
||||
SignalStore.backup.lastCheckInSnoozeMillis = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the "Your media will be deleted today" sheet should be displayed.
|
||||
*/
|
||||
suspend fun shouldDisplayYourMediaWillBeDeletedTodaySheet(): Boolean {
|
||||
if (shouldNotDisplayBackupFailedMessaging() || !SignalStore.backup.optimizeStorage) {
|
||||
return false
|
||||
}
|
||||
|
||||
val paidType = try {
|
||||
withContext(Dispatchers.IO) {
|
||||
getPaidType()
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Log.w(TAG, "Failed to retrieve paid type.", e)
|
||||
return false
|
||||
}
|
||||
|
||||
if (paidType == null) {
|
||||
Log.w(TAG, "Paid type is not available on this device.")
|
||||
return false
|
||||
}
|
||||
|
||||
val lastCheckIn = SignalStore.backup.lastCheckInMillis.milliseconds
|
||||
if (lastCheckIn == 0.milliseconds) {
|
||||
Log.w(TAG, "LastCheckIn has not yet been set.")
|
||||
return false
|
||||
}
|
||||
|
||||
val lastSnoozeTime = SignalStore.backup.lastCheckInSnoozeMillis.milliseconds
|
||||
val now = System.currentTimeMillis().milliseconds
|
||||
val mediaTtl = paidType.mediaTtl
|
||||
val mediaExpiration = lastCheckIn + mediaTtl
|
||||
|
||||
val isNowAfterSnooze = now < lastSnoozeTime || now >= lastSnoozeTime + 4.hours
|
||||
val isNowWithin24HoursOfMediaExpiration = now < mediaExpiration && (mediaExpiration - now) <= 1.days
|
||||
|
||||
return isNowAfterSnooze && isNowWithin24HoursOfMediaExpiration
|
||||
}
|
||||
|
||||
private fun shouldNotDisplayBackupFailedMessaging(): Boolean {
|
||||
return !RemoteConfig.messageBackups || !SignalStore.backup.areBackupsEnabled || !SignalStore.backup.hasBackupBeenUploaded
|
||||
}
|
||||
@@ -1178,7 +1222,7 @@ object BackupRepository {
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getFreeType(): MessageBackupsType {
|
||||
private suspend fun getFreeType(): MessageBackupsType.Free {
|
||||
val config = getSubscriptionsConfiguration()
|
||||
|
||||
return MessageBackupsType.Free(
|
||||
@@ -1186,7 +1230,7 @@ object BackupRepository {
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun getPaidType(): MessageBackupsType? {
|
||||
private suspend fun getPaidType(): MessageBackupsType.Paid? {
|
||||
val config = getSubscriptionsConfiguration()
|
||||
val product = AppDependencies.billingApi.queryProduct() ?: return null
|
||||
val backupLevelConfiguration = config.backupConfiguration.backupLevelConfigurationMap[SubscriptionsConfiguration.BACKUPS_LEVEL] ?: return null
|
||||
|
||||
@@ -154,6 +154,7 @@ class BackupAlertBottomSheet : UpgradeToPaidTierBottomSheet() {
|
||||
|
||||
when (backupAlert) {
|
||||
is BackupAlert.CouldNotCompleteBackup -> BackupRepository.markBackupFailedSheetDismissed()
|
||||
is BackupAlert.MediaWillBeDeletedToday -> BackupRepository.snoozeYourMediaWillBeDeletedTodaySheet()
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@ object BackupAlertDelegate {
|
||||
BackupAlertBottomSheet.create(BackupAlert.CouldNotCompleteBackup(daysSinceLastBackup = SignalStore.backup.daysSinceLastBackup)).show(fragmentManager, null)
|
||||
}
|
||||
|
||||
// TODO [backups] Check if media will be deleted within 24hrs and display warning sheet.
|
||||
|
||||
// TODO [backups]
|
||||
// Get unnotified backup download failures & display sheet
|
||||
if (BackupRepository.shouldDisplayYourMediaWillBeDeletedTodaySheet()) {
|
||||
BackupAlertBottomSheet.create(BackupAlert.MediaWillBeDeletedToday)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user