Avoid crash when not connected to the network.

This commit is contained in:
Alex Hart
2025-07-08 15:51:32 -03:00
parent 6d58e89c18
commit e6ca41c0f9
4 changed files with 48 additions and 47 deletions

View File

@@ -194,7 +194,12 @@ object BackupStateRepository {
private suspend fun getFreeBackupState(): BackupState {
val type = withContext(Dispatchers.IO) {
BackupRepository.getBackupsType(MessageBackupTier.FREE) as MessageBackupsType.Free
BackupRepository.getBackupsType(MessageBackupTier.FREE) as MessageBackupsType.Free?
}
if (type == null) {
Log.w(TAG, "Failed to load FREE type. Possible network error.")
return BackupState.Error
}
val backupState = if (SignalStore.backup.areBackupsEnabled) {
@@ -213,7 +218,7 @@ object BackupStateRepository {
* @return A paid type, or null if we were unable to get the backup level configuration.
*/
private fun buildPaidTypeFromSubscription(subscription: ActiveSubscription.Subscription): MessageBackupsType.Paid? {
val config = BackupRepository.getBackupLevelConfiguration() ?: return null
val config = BackupRepository.getBackupLevelConfiguration().successOrThrow()
val price = FiatMoney.fromSignalNetworkAmount(subscription.amount, Currency.getInstance(subscription.currency))
return MessageBackupsType.Paid(
@@ -229,7 +234,7 @@ object BackupStateRepository {
* @return A paid type, or null if we were unable to get the backup level configuration.
*/
private fun buildPaidTypeFromInAppPayment(inAppPayment: InAppPaymentTable.InAppPayment): MessageBackupsType.Paid? {
val config = BackupRepository.getBackupLevelConfiguration() ?: return null
val config = BackupRepository.getBackupLevelConfiguration().successOrThrow()
val price = inAppPayment.data.amount!!.toFiatMoney()
return MessageBackupsType.Paid(
@@ -246,7 +251,7 @@ object BackupStateRepository {
* @return A paid type, or null if we were unable to get the backup level configuration.
*/
private fun buildPaidTypeWithoutPricing(): MessageBackupsType? {
val config = BackupRepository.getBackupLevelConfiguration() ?: return null
val config = BackupRepository.getBackupLevelConfiguration().successOrThrow()
return MessageBackupsType.Paid(
pricePerMonth = FiatMoney(BigDecimal.ZERO, Currency.getInstance(Locale.getDefault())),