discord-jadx/app/src/main/java/com/discord/widgets/auth/WidgetRemoteAuthViewModel.java

331 lines
15 KiB
Java

package com.discord.widgets.auth;
import android.content.Context;
import androidx.lifecycle.ViewModelKt;
import c.q.a.k.a;
import com.discord.app.AppViewModel;
import com.discord.models.domain.ModelRemoteAuthHandshake;
import com.discord.restapi.RestAPIParams;
import com.discord.utilities.error.Error;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import d0.g0.t;
import d0.l;
import d0.w.g.c;
import d0.w.h.a.e;
import d0.w.h.a.k;
import d0.z.d.m;
import d0.z.d.o;
import java.util.Objects;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlinx.coroutines.CoroutineScope;
import rx.subjects.BehaviorSubject;
/* compiled from: WidgetRemoteAuthViewModel.kt */
public final class WidgetRemoteAuthViewModel extends AppViewModel<ViewState> {
private final RestAPI restAPI;
private final BehaviorSubject<Boolean> temporaryBehaviorSubject;
/* compiled from: WidgetRemoteAuthViewModel.kt */
/* renamed from: com.discord.widgets.auth.WidgetRemoteAuthViewModel$1 reason: invalid class name */
public static final class AnonymousClass1 extends o implements Function1<ModelRemoteAuthHandshake, Unit> {
public final /* synthetic */ WidgetRemoteAuthViewModel this$0;
/* compiled from: WidgetRemoteAuthViewModel.kt */
@e(c = "com.discord.widgets.auth.WidgetRemoteAuthViewModel$1$1", f = "WidgetRemoteAuthViewModel.kt", l = {54}, m = "invokeSuspend")
/* renamed from: com.discord.widgets.auth.WidgetRemoteAuthViewModel$1$1 reason: invalid class name */
public static final class AnonymousClass1 extends k implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
public final /* synthetic */ ModelRemoteAuthHandshake $handshakeData;
public int label;
public final /* synthetic */ AnonymousClass1 this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public AnonymousClass1(AnonymousClass1 r1, ModelRemoteAuthHandshake modelRemoteAuthHandshake, Continuation continuation) {
super(2, continuation);
this.this$0 = r1;
this.$handshakeData = modelRemoteAuthHandshake;
}
@Override // d0.w.h.a.a
public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
m.checkNotNullParameter(continuation, "completion");
return new AnonymousClass1(this.this$0, this.$handshakeData, continuation);
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
@Override // kotlin.jvm.functions.Function2
public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Unit> continuation) {
return ((AnonymousClass1) create(coroutineScope, continuation)).invokeSuspend(Unit.a);
}
@Override // d0.w.h.a.a
public final Object invokeSuspend(Object obj) {
Object coroutine_suspended = c.getCOROUTINE_SUSPENDED();
int i = this.label;
if (i == 0) {
l.throwOnFailure(obj);
this.label = 1;
if (a.n(1000, this) == coroutine_suspended) {
return coroutine_suspended;
}
} else if (i == 1) {
l.throwOnFailure(obj);
} else {
throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
}
WidgetRemoteAuthViewModel widgetRemoteAuthViewModel = this.this$0.this$0;
String handshakeToken = this.$handshakeData.getHandshakeToken();
BehaviorSubject access$getTemporaryBehaviorSubject$p = WidgetRemoteAuthViewModel.access$getTemporaryBehaviorSubject$p(this.this$0.this$0);
m.checkNotNullExpressionValue(access$getTemporaryBehaviorSubject$p, "temporaryBehaviorSubject");
Object n0 = access$getTemporaryBehaviorSubject$p.n0();
m.checkNotNullExpressionValue(n0, "temporaryBehaviorSubject.value");
WidgetRemoteAuthViewModel.access$updateViewState(widgetRemoteAuthViewModel, new ViewState.Loaded(handshakeToken, ((Boolean) n0).booleanValue(), true));
return Unit.a;
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public AnonymousClass1(WidgetRemoteAuthViewModel widgetRemoteAuthViewModel) {
super(1);
this.this$0 = widgetRemoteAuthViewModel;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(ModelRemoteAuthHandshake modelRemoteAuthHandshake) {
invoke(modelRemoteAuthHandshake);
return Unit.a;
}
public final void invoke(ModelRemoteAuthHandshake modelRemoteAuthHandshake) {
m.checkNotNullParameter(modelRemoteAuthHandshake, "handshakeData");
WidgetRemoteAuthViewModel widgetRemoteAuthViewModel = this.this$0;
String handshakeToken = modelRemoteAuthHandshake.getHandshakeToken();
BehaviorSubject access$getTemporaryBehaviorSubject$p = WidgetRemoteAuthViewModel.access$getTemporaryBehaviorSubject$p(this.this$0);
m.checkNotNullExpressionValue(access$getTemporaryBehaviorSubject$p, "temporaryBehaviorSubject");
Object n0 = access$getTemporaryBehaviorSubject$p.n0();
m.checkNotNullExpressionValue(n0, "temporaryBehaviorSubject.value");
WidgetRemoteAuthViewModel.access$updateViewState(widgetRemoteAuthViewModel, new ViewState.Loaded(handshakeToken, ((Boolean) n0).booleanValue(), false));
a.G(ViewModelKt.getViewModelScope(this.this$0), null, null, new AnonymousClass1(this, modelRemoteAuthHandshake, null), 3, null);
}
}
/* compiled from: WidgetRemoteAuthViewModel.kt */
/* renamed from: com.discord.widgets.auth.WidgetRemoteAuthViewModel$2 reason: invalid class name */
public static final class AnonymousClass2 extends o implements Function1<Error, Unit> {
public final /* synthetic */ WidgetRemoteAuthViewModel this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public AnonymousClass2(WidgetRemoteAuthViewModel widgetRemoteAuthViewModel) {
super(1);
this.this$0 = widgetRemoteAuthViewModel;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(Error error) {
invoke(error);
return Unit.a;
}
public final void invoke(Error error) {
m.checkNotNullParameter(error, "it");
Error.Response response = error.getResponse();
m.checkNotNullExpressionValue(response, "it.response");
if (response.getCode() == 10056) {
WidgetRemoteAuthViewModel.access$updateViewState(this.this$0, ViewState.Failed.INSTANCE);
}
}
}
/* compiled from: WidgetRemoteAuthViewModel.kt */
public static abstract class ViewState {
/* compiled from: WidgetRemoteAuthViewModel.kt */
public static final class Failed extends ViewState {
public static final Failed INSTANCE = new Failed();
private Failed() {
super(null);
}
}
/* compiled from: WidgetRemoteAuthViewModel.kt */
public static final class Loaded extends ViewState {
private final String handshakeToken;
private final boolean isTemporary;
private final boolean loginAllowed;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Loaded(String str, boolean z2, boolean z3) {
super(null);
m.checkNotNullParameter(str, "handshakeToken");
this.handshakeToken = str;
this.isTemporary = z2;
this.loginAllowed = z3;
}
public static /* synthetic */ Loaded copy$default(Loaded loaded, String str, boolean z2, boolean z3, int i, Object obj) {
if ((i & 1) != 0) {
str = loaded.handshakeToken;
}
if ((i & 2) != 0) {
z2 = loaded.isTemporary;
}
if ((i & 4) != 0) {
z3 = loaded.loginAllowed;
}
return loaded.copy(str, z2, z3);
}
public final String component1() {
return this.handshakeToken;
}
public final boolean component2() {
return this.isTemporary;
}
public final boolean component3() {
return this.loginAllowed;
}
public final Loaded copy(String str, boolean z2, boolean z3) {
m.checkNotNullParameter(str, "handshakeToken");
return new Loaded(str, z2, z3);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Loaded)) {
return false;
}
Loaded loaded = (Loaded) obj;
return m.areEqual(this.handshakeToken, loaded.handshakeToken) && this.isTemporary == loaded.isTemporary && this.loginAllowed == loaded.loginAllowed;
}
public final String getHandshakeToken() {
return this.handshakeToken;
}
public final boolean getLoginAllowed() {
return this.loginAllowed;
}
public int hashCode() {
String str = this.handshakeToken;
int hashCode = (str != null ? str.hashCode() : 0) * 31;
boolean z2 = this.isTemporary;
int i = 1;
if (z2) {
z2 = true;
}
int i2 = z2 ? 1 : 0;
int i3 = z2 ? 1 : 0;
int i4 = z2 ? 1 : 0;
int i5 = (hashCode + i2) * 31;
boolean z3 = this.loginAllowed;
if (!z3) {
i = z3 ? 1 : 0;
}
return i5 + i;
}
public final boolean isTemporary() {
return this.isTemporary;
}
public String toString() {
StringBuilder K = c.d.b.a.a.K("Loaded(handshakeToken=");
K.append(this.handshakeToken);
K.append(", isTemporary=");
K.append(this.isTemporary);
K.append(", loginAllowed=");
return c.d.b.a.a.F(K, this.loginAllowed, ")");
}
}
/* compiled from: WidgetRemoteAuthViewModel.kt */
public static final class Loading extends ViewState {
public static final Loading INSTANCE = new Loading();
private Loading() {
super(null);
}
}
/* compiled from: WidgetRemoteAuthViewModel.kt */
public static final class Succeeded extends ViewState {
public static final Succeeded INSTANCE = new Succeeded();
private Succeeded() {
super(null);
}
}
private ViewState() {
}
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public WidgetRemoteAuthViewModel(String str, RestAPI restAPI) {
super(ViewState.Loading.INSTANCE);
m.checkNotNullParameter(str, "fingerprint");
m.checkNotNullParameter(restAPI, "restAPI");
this.restAPI = restAPI;
this.temporaryBehaviorSubject = BehaviorSubject.l0(Boolean.TRUE);
if (t.isBlank(str)) {
updateViewState(ViewState.Failed.INSTANCE);
return;
}
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn(restAPI.postRemoteAuthInitialize(new RestAPIParams.RemoteAuthInitialize(str)), false), this, null, 2, null), WidgetRemoteAuthViewModel.class, (Context) null, (Function1) null, new AnonymousClass2(this), (Function0) null, (Function0) null, new AnonymousClass1(this), 54, (Object) null);
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ WidgetRemoteAuthViewModel(String str, RestAPI restAPI, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(str, (i & 2) != 0 ? RestAPI.Companion.getApi() : restAPI);
}
public static final /* synthetic */ BehaviorSubject access$getTemporaryBehaviorSubject$p(WidgetRemoteAuthViewModel widgetRemoteAuthViewModel) {
return widgetRemoteAuthViewModel.temporaryBehaviorSubject;
}
public static final /* synthetic */ void access$updateViewState(WidgetRemoteAuthViewModel widgetRemoteAuthViewModel, ViewState viewState) {
widgetRemoteAuthViewModel.updateViewState(viewState);
}
public final void cancelLogin() {
if (getViewState() instanceof ViewState.Loaded) {
RestAPI restAPI = this.restAPI;
ViewState viewState = getViewState();
Objects.requireNonNull(viewState, "null cannot be cast to non-null type com.discord.widgets.auth.WidgetRemoteAuthViewModel.ViewState.Loaded");
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(restAPI.postRemoteAuthCancel(new RestAPIParams.RemoteAuthCancel(((ViewState.Loaded) viewState).getHandshakeToken())), false, 1, null), WidgetRemoteAuthViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, WidgetRemoteAuthViewModel$cancelLogin$1.INSTANCE, 62, (Object) null);
}
}
public final void remoteLogin() {
if (getViewState() instanceof ViewState.Loaded) {
RestAPI restAPI = this.restAPI;
ViewState viewState = getViewState();
Objects.requireNonNull(viewState, "null cannot be cast to non-null type com.discord.widgets.auth.WidgetRemoteAuthViewModel.ViewState.Loaded");
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn(restAPI.postRemoteAuthFinish(new RestAPIParams.RemoteAuthFinish(false, ((ViewState.Loaded) viewState).getHandshakeToken())), false), WidgetRemoteAuthViewModel.class, (Context) null, (Function1) null, new WidgetRemoteAuthViewModel$remoteLogin$2(this), (Function0) null, (Function0) null, new WidgetRemoteAuthViewModel$remoteLogin$1(this), 54, (Object) null);
}
}
public final void toggleTemporary(boolean z2) {
this.temporaryBehaviorSubject.onNext(Boolean.valueOf(z2));
}
}