mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-21 02:08:40 +00:00
Wire in NetworkResult for Types.
This commit is contained in:
committed by
Jeffrey Starke
parent
7753aadbf0
commit
b45fb28dbe
@@ -1611,20 +1611,18 @@ object BackupRepository {
|
||||
}
|
||||
|
||||
suspend fun getAvailableBackupsTypes(availableBackupTiers: List<MessageBackupTier>): List<MessageBackupsType> {
|
||||
return availableBackupTiers.mapNotNull { getBackupsType(it) }
|
||||
return availableBackupTiers.mapNotNull {
|
||||
val type = getBackupsType(it)
|
||||
|
||||
if (type is NetworkResult.Success) type.result else null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getBackupsType(tier: MessageBackupTier): MessageBackupsType? {
|
||||
val result = when (tier) {
|
||||
private suspend fun getBackupsType(tier: MessageBackupTier): NetworkResult<out MessageBackupsType> {
|
||||
return when (tier) {
|
||||
MessageBackupTier.FREE -> getFreeType()
|
||||
MessageBackupTier.PAID -> getPaidType()
|
||||
}
|
||||
|
||||
return if (result is NetworkResult.Success) {
|
||||
result.result
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@@ -1642,7 +1640,7 @@ object BackupRepository {
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun getFreeType(): NetworkResult<MessageBackupsType.Free> {
|
||||
fun getFreeType(): NetworkResult<MessageBackupsType.Free> {
|
||||
return AppDependencies.donationsApi
|
||||
.getDonationsConfiguration(Locale.getDefault())
|
||||
.map {
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.thoughtcrime.securesms.database.InAppPaymentTable
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription
|
||||
import java.math.BigDecimal
|
||||
import java.util.Currency
|
||||
@@ -118,10 +119,12 @@ object BackupStateRepository {
|
||||
private suspend fun getPaidBackupState(lastPurchase: InAppPaymentTable.InAppPayment?): BackupState {
|
||||
Log.d(TAG, "Attempting to retrieve subscription details for active PAID backup.")
|
||||
|
||||
val type = withContext(Dispatchers.IO) {
|
||||
BackupRepository.getBackupsType(MessageBackupTier.PAID) as? MessageBackupsType.Paid
|
||||
val typeResult = withContext(Dispatchers.IO) {
|
||||
BackupRepository.getPaidType()
|
||||
}
|
||||
|
||||
val type = if (typeResult is NetworkResult.Success) typeResult.result else null
|
||||
|
||||
Log.d(TAG, "Attempting to retrieve current subscription...")
|
||||
val activeSubscription = withContext(Dispatchers.IO) {
|
||||
RecurringInAppPaymentRepository.getActiveSubscriptionSync(InAppPaymentSubscriberRecord.Type.BACKUP)
|
||||
@@ -194,18 +197,18 @@ object BackupStateRepository {
|
||||
|
||||
private suspend fun getFreeBackupState(): BackupState {
|
||||
val type = withContext(Dispatchers.IO) {
|
||||
BackupRepository.getBackupsType(MessageBackupTier.FREE) as MessageBackupsType.Free?
|
||||
BackupRepository.getFreeType()
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
Log.w(TAG, "Failed to load FREE type. Possible network error.")
|
||||
if (type !is NetworkResult.Success) {
|
||||
Log.w(TAG, "Failed to load FREE type.", type.getCause())
|
||||
return BackupState.Error
|
||||
}
|
||||
|
||||
val backupState = if (SignalStore.backup.areBackupsEnabled) {
|
||||
BackupState.ActiveFree(type)
|
||||
BackupState.ActiveFree(type.result)
|
||||
} else {
|
||||
BackupState.Inactive(type)
|
||||
BackupState.Inactive(type.result)
|
||||
}
|
||||
|
||||
Log.d(TAG, "Updating UI state with $backupState FREE tier.")
|
||||
|
||||
@@ -31,9 +31,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.backup.v2.ui.subscription.MessageBackupsType
|
||||
import org.thoughtcrime.securesms.banner.banners.MediaRestoreProgressBanner
|
||||
import org.thoughtcrime.securesms.components.settings.app.backups.BackupStateRepository
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository
|
||||
@@ -47,6 +45,7 @@ import org.thoughtcrime.securesms.keyvalue.protos.ArchiveUploadProgressState
|
||||
import org.thoughtcrime.securesms.service.MessageBackupListener
|
||||
import org.thoughtcrime.securesms.util.RemoteConfig
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
/**
|
||||
@@ -233,10 +232,10 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
|
||||
|
||||
private suspend fun performStateRefresh(lastPurchase: InAppPaymentTable.InAppPayment?) {
|
||||
if (BackupRepository.shouldDisplayOutOfStorageSpaceUx()) {
|
||||
val paidType = BackupRepository.getBackupsType(MessageBackupTier.PAID) as? MessageBackupsType.Paid
|
||||
val paidType = BackupRepository.getPaidType()
|
||||
|
||||
if (paidType != null) {
|
||||
val remoteStorageAllowance = paidType.storageAllowanceBytes.bytes
|
||||
if (paidType is NetworkResult.Success) {
|
||||
val remoteStorageAllowance = paidType.result.storageAllowanceBytes.bytes
|
||||
val estimatedSize = SignalDatabase.attachments.getEstimatedArchiveMediaSize().bytes
|
||||
|
||||
if (estimatedSize + 300.mebiBytes <= remoteStorageAllowance) {
|
||||
@@ -248,6 +247,8 @@ class RemoteBackupsSettingsViewModel : ViewModel() {
|
||||
totalAllowedStorageSpace = estimatedSize.toUnitString()
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "Failed to load PAID type.", paidType.getCause())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user