mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Access configuration via cache layer when evaluating state.
This commit is contained in:
@@ -1830,8 +1830,9 @@ object BackupRepository {
|
||||
|
||||
@WorkerThread
|
||||
fun getBackupLevelConfiguration(): NetworkResult<SubscriptionsConfiguration.BackupLevelConfiguration> {
|
||||
return AppDependencies.donationsApi
|
||||
return AppDependencies.donationsService
|
||||
.getDonationsConfiguration(Locale.getDefault())
|
||||
.toNetworkResult()
|
||||
.then {
|
||||
val config = it.backupConfiguration.backupLevelConfigurationMap[SubscriptionsConfiguration.BACKUPS_LEVEL]
|
||||
if (config != null) {
|
||||
@@ -1844,8 +1845,9 @@ object BackupRepository {
|
||||
|
||||
@WorkerThread
|
||||
fun getFreeType(): NetworkResult<MessageBackupsType.Free> {
|
||||
return AppDependencies.donationsApi
|
||||
return AppDependencies.donationsService
|
||||
.getDonationsConfiguration(Locale.getDefault())
|
||||
.toNetworkResult()
|
||||
.map {
|
||||
MessageBackupsType.Free(
|
||||
mediaRetentionDays = it.backupConfiguration.freeTierMediaDays
|
||||
|
||||
@@ -31,12 +31,16 @@ import java.util.Locale
|
||||
|
||||
/**
|
||||
* One-stop shop for Signal service calls related to in-app payments.
|
||||
*
|
||||
* Be sure to check for cached versions of these methods in DonationsService before calling these methods elsewhere.
|
||||
*/
|
||||
class DonationsApi(private val authWebSocket: SignalWebSocket.AuthenticatedWebSocket, private val unauthWebSocket: SignalWebSocket.UnauthenticatedWebSocket) {
|
||||
|
||||
/**
|
||||
* Get configuration data associated with donations, like gift, one-time, and monthly levels, etc.
|
||||
*
|
||||
* Note, this will skip cached values, causing us to hit the network more than necessary. Consider accessing this method via the DonationsService instead.
|
||||
*
|
||||
* GET /v1/subscription/configuration
|
||||
* - 200: Success
|
||||
*/
|
||||
|
||||
@@ -2,11 +2,14 @@ package org.whispersystems.signalservice.internal;
|
||||
|
||||
|
||||
|
||||
import org.whispersystems.signalservice.api.NetworkResult;
|
||||
import org.whispersystems.signalservice.api.NetworkResultUtil;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
||||
import org.whispersystems.signalservice.api.util.Preconditions;
|
||||
import org.whispersystems.signalservice.internal.websocket.WebsocketResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@@ -84,6 +87,25 @@ public final class ServiceResponse<Result> {
|
||||
}
|
||||
}
|
||||
|
||||
public NetworkResult<Result> toNetworkResult() {
|
||||
if (result.isPresent()) {
|
||||
return new NetworkResult.Success<>(result.get());
|
||||
} else if (applicationError.isPresent()) {
|
||||
return new NetworkResult.ApplicationError<>(applicationError.get());
|
||||
} else if (executionError.isPresent()) {
|
||||
Throwable error = executionError.get();
|
||||
if (error instanceof NonSuccessfulResponseCodeException) {
|
||||
return new NetworkResult.StatusCodeError<>((NonSuccessfulResponseCodeException) error);
|
||||
} else if (error instanceof IOException) {
|
||||
return new NetworkResult.NetworkError<>((IOException) error);
|
||||
} else {
|
||||
return new NetworkResult.ApplicationError<>(error);
|
||||
}
|
||||
} else {
|
||||
throw new AssertionError("Should never get here");
|
||||
}
|
||||
}
|
||||
|
||||
public Result getResultOrThrow() throws Throwable {
|
||||
if (result.isPresent()) {
|
||||
return result.get();
|
||||
|
||||
Reference in New Issue
Block a user