mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-02 14:43:09 +01:00
Access configuration via cache layer when evaluating state.
This commit is contained in:
@@ -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