discord-jadx/app/src/main/java/com/discord/gateway/GatewayDiscovery.java

107 lines
5.0 KiB
Java

package com.discord.gateway;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import c0.z.d.m;
import com.discord.utilities.networking.Backoff;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import rx.Observable;
import rx.Scheduler;
import rx.Subscription;
/* compiled from: GatewayDiscovery.kt */
public final class GatewayDiscovery {
private final Backoff backoff;
private String gatewayUrl;
private Subscription gatewayUrlDiscoverySubscription;
private final Observable<String> gatewayUrlProvider;
private final Function1<String, Unit> log;
private final Scheduler scheduler;
/* compiled from: GatewayDiscovery.kt */
public static final class Cache {
private static final String GATEWAY_URL_CACHE_KEY = "GATEWAY_URL_CACHE_KEY";
public static final Cache INSTANCE = new Cache();
private static SharedPreferences sharedPreferences;
private Cache() {
}
public final String getGatewayUrl() {
SharedPreferences sharedPreferences2 = sharedPreferences;
if (sharedPreferences2 == null) {
m.throwUninitializedPropertyAccessException("sharedPreferences");
}
return sharedPreferences2.getString(GATEWAY_URL_CACHE_KEY, null);
}
public final void init(Context context) {
m.checkNotNullParameter(context, "context");
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
m.checkNotNullExpressionValue(defaultSharedPreferences, "PreferenceManager.getDef…haredPreferences(context)");
sharedPreferences = defaultSharedPreferences;
}
public final void setGatewayUrl(String str) {
SharedPreferences sharedPreferences2 = sharedPreferences;
if (sharedPreferences2 == null) {
m.throwUninitializedPropertyAccessException("sharedPreferences");
}
SharedPreferences.Editor edit = sharedPreferences2.edit();
m.checkNotNullExpressionValue(edit, "editor");
edit.putString(GATEWAY_URL_CACHE_KEY, str);
edit.apply();
}
}
/* JADX DEBUG: Multi-variable search result rejected for r5v0, resolved type: kotlin.jvm.functions.Function1<? super java.lang.String, kotlin.Unit> */
/* JADX WARN: Multi-variable type inference failed */
public GatewayDiscovery(Context context, Scheduler scheduler, Backoff backoff, Function1<? super String, Unit> function1, Observable<String> observable) {
m.checkNotNullParameter(context, "context");
m.checkNotNullParameter(scheduler, "scheduler");
m.checkNotNullParameter(backoff, "backoff");
m.checkNotNullParameter(function1, "log");
m.checkNotNullParameter(observable, "gatewayUrlProvider");
this.scheduler = scheduler;
this.backoff = backoff;
this.log = function1;
this.gatewayUrlProvider = observable;
Cache cache = Cache.INSTANCE;
cache.init(context);
this.gatewayUrl = cache.getGatewayUrl();
}
public static final /* synthetic */ String access$getGatewayUrl$p(GatewayDiscovery gatewayDiscovery) {
return gatewayDiscovery.gatewayUrl;
}
public static final /* synthetic */ Function1 access$getLog$p(GatewayDiscovery gatewayDiscovery) {
return gatewayDiscovery.log;
}
public static final /* synthetic */ void access$setGatewayUrl$p(GatewayDiscovery gatewayDiscovery, String str) {
gatewayDiscovery.gatewayUrl = str;
}
public final void discoverGatewayUrl(Function1<? super String, Unit> function1, Function1<? super Throwable, Unit> function12) {
String str;
m.checkNotNullParameter(function1, "onSuccess");
m.checkNotNullParameter(function12, "onFailure");
if (this.backoff.hasReachedFailureThreshold() || (str = this.gatewayUrl) == null) {
this.log.invoke("Discovering gateway url.");
GatewayDiscovery$discoverGatewayUrl$1 gatewayDiscovery$discoverGatewayUrl$1 = new GatewayDiscovery$discoverGatewayUrl$1(this, function12);
GatewayDiscovery$discoverGatewayUrl$2 gatewayDiscovery$discoverGatewayUrl$2 = new GatewayDiscovery$discoverGatewayUrl$2(this, gatewayDiscovery$discoverGatewayUrl$1, function1);
Subscription subscription = this.gatewayUrlDiscoverySubscription;
if (subscription != null) {
subscription.unsubscribe();
}
this.gatewayUrlDiscoverySubscription = this.gatewayUrlProvider.I(this.scheduler).W(new GatewayDiscovery$sam$rx_functions_Action1$0(new GatewayDiscovery$discoverGatewayUrl$3(gatewayDiscovery$discoverGatewayUrl$2)), new GatewayDiscovery$sam$rx_functions_Action1$0(new GatewayDiscovery$discoverGatewayUrl$4(gatewayDiscovery$discoverGatewayUrl$1)));
return;
}
Function1<String, Unit> function13 = this.log;
function13.invoke("Using sticky gateway url: " + str);
function1.invoke(str);
}
}