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

507 lines
20 KiB
Java

package com.discord.widgets.auth;
import android.content.Context;
import androidx.annotation.MainThread;
import c.d.b.a.a;
import com.discord.api.channel.Channel;
import com.discord.api.user.NsfwAllowance;
import com.discord.app.AppViewModel;
import com.discord.restapi.RestAPIParams;
import com.discord.stores.StoreAuthentication;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreUser;
import com.discord.utilities.analytics.AnalyticsTracker;
import com.discord.utilities.birthday.BirthdayHelper;
import com.discord.utilities.channel.ChannelSelector;
import com.discord.utilities.error.Error;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.time.TimeUtils;
import d0.t.n;
import d0.t.u;
import d0.z.d.m;
import d0.z.d.o;
import java.util.List;
import java.util.Map;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
import rx.subjects.PublishSubject;
/* compiled from: WidgetAgeVerifyViewModel.kt */
public final class WidgetAgeVerifyViewModel extends AppViewModel<ViewState> {
public static final Companion Companion = new Companion(null);
private final PublishSubject<Event> eventsSubject;
private final RestAPI restAPI;
private final StoreAuthentication storeAuth;
/* compiled from: WidgetAgeVerifyViewModel.kt */
/* renamed from: com.discord.widgets.auth.WidgetAgeVerifyViewModel$1 reason: invalid class name */
public static final class AnonymousClass1 extends o implements Function1<StoreState, Unit> {
public final /* synthetic */ WidgetAgeVerifyViewModel this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public AnonymousClass1(WidgetAgeVerifyViewModel widgetAgeVerifyViewModel) {
super(1);
this.this$0 = widgetAgeVerifyViewModel;
}
/* 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(StoreState storeState) {
invoke(storeState);
return Unit.a;
}
public final void invoke(StoreState storeState) {
m.checkNotNullParameter(storeState, "storeState");
WidgetAgeVerifyViewModel.access$handleStoreState(this.this$0, storeState);
}
}
/* compiled from: WidgetAgeVerifyViewModel.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public final Observable<StoreState> observeStores() {
StoreStream.Companion companion = StoreStream.Companion;
Observable<StoreState> i = Observable.i(StoreUser.observeMe$default(companion.getUsers(), false, 1, null), companion.getAuthentication().observeIsAuthed$app_productionBetaRelease(), companion.getChannelsSelected().observeSelectedChannel().Y(WidgetAgeVerifyViewModel$Companion$observeStores$1.INSTANCE), WidgetAgeVerifyViewModel$Companion$observeStores$2.INSTANCE);
m.checkNotNullExpressionValue(i, "Observable.combineLatest…hed\n )\n }");
return i;
}
}
/* compiled from: WidgetAgeVerifyViewModel.kt */
public static abstract class Event {
/* compiled from: WidgetAgeVerifyViewModel.kt */
public static final class Verified extends Event {
public static final Verified INSTANCE = new Verified();
private Verified() {
super(null);
}
}
private Event() {
}
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: WidgetAgeVerifyViewModel.kt */
public static final class StoreState {
private final boolean authed;
private final NsfwAllowance nsfwAllowed;
private final Channel safeChannel;
public StoreState(Channel channel, NsfwAllowance nsfwAllowance, boolean z2) {
m.checkNotNullParameter(nsfwAllowance, "nsfwAllowed");
this.safeChannel = channel;
this.nsfwAllowed = nsfwAllowance;
this.authed = z2;
}
public static /* synthetic */ StoreState copy$default(StoreState storeState, Channel channel, NsfwAllowance nsfwAllowance, boolean z2, int i, Object obj) {
if ((i & 1) != 0) {
channel = storeState.safeChannel;
}
if ((i & 2) != 0) {
nsfwAllowance = storeState.nsfwAllowed;
}
if ((i & 4) != 0) {
z2 = storeState.authed;
}
return storeState.copy(channel, nsfwAllowance, z2);
}
public final Channel component1() {
return this.safeChannel;
}
public final NsfwAllowance component2() {
return this.nsfwAllowed;
}
public final boolean component3() {
return this.authed;
}
public final StoreState copy(Channel channel, NsfwAllowance nsfwAllowance, boolean z2) {
m.checkNotNullParameter(nsfwAllowance, "nsfwAllowed");
return new StoreState(channel, nsfwAllowance, z2);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof StoreState)) {
return false;
}
StoreState storeState = (StoreState) obj;
return m.areEqual(this.safeChannel, storeState.safeChannel) && m.areEqual(this.nsfwAllowed, storeState.nsfwAllowed) && this.authed == storeState.authed;
}
public final boolean getAuthed() {
return this.authed;
}
public final NsfwAllowance getNsfwAllowed() {
return this.nsfwAllowed;
}
public final Channel getSafeChannel() {
return this.safeChannel;
}
public int hashCode() {
Channel channel = this.safeChannel;
int i = 0;
int hashCode = (channel != null ? channel.hashCode() : 0) * 31;
NsfwAllowance nsfwAllowance = this.nsfwAllowed;
if (nsfwAllowance != null) {
i = nsfwAllowance.hashCode();
}
int i2 = (hashCode + i) * 31;
boolean z2 = this.authed;
if (z2) {
z2 = true;
}
int i3 = z2 ? 1 : 0;
int i4 = z2 ? 1 : 0;
int i5 = z2 ? 1 : 0;
return i2 + i3;
}
public String toString() {
StringBuilder K = a.K("StoreState(safeChannel=");
K.append(this.safeChannel);
K.append(", nsfwAllowed=");
K.append(this.nsfwAllowed);
K.append(", authed=");
return a.F(K, this.authed, ")");
}
}
/* compiled from: WidgetAgeVerifyViewModel.kt */
public static final class ViewState {
private Long dateOfBirth;
private final int displayedChild;
private final Integer errorStringId;
private final boolean isSubmitting;
private final Channel safeChannel;
private final boolean shouldClose;
private String underageMessage;
public ViewState(boolean z2, Integer num, int i, Long l, String str, Channel channel, boolean z3) {
this.isSubmitting = z2;
this.errorStringId = num;
this.displayedChild = i;
this.dateOfBirth = l;
this.underageMessage = str;
this.safeChannel = channel;
this.shouldClose = z3;
}
public static /* synthetic */ ViewState copy$default(ViewState viewState, boolean z2, Integer num, int i, Long l, String str, Channel channel, boolean z3, int i2, Object obj) {
if ((i2 & 1) != 0) {
z2 = viewState.isSubmitting;
}
if ((i2 & 2) != 0) {
num = viewState.errorStringId;
}
if ((i2 & 4) != 0) {
i = viewState.displayedChild;
}
if ((i2 & 8) != 0) {
l = viewState.dateOfBirth;
}
if ((i2 & 16) != 0) {
str = viewState.underageMessage;
}
if ((i2 & 32) != 0) {
channel = viewState.safeChannel;
}
if ((i2 & 64) != 0) {
z3 = viewState.shouldClose;
}
return viewState.copy(z2, num, i, l, str, channel, z3);
}
public final boolean component1() {
return this.isSubmitting;
}
public final Integer component2() {
return this.errorStringId;
}
public final int component3() {
return this.displayedChild;
}
public final Long component4() {
return this.dateOfBirth;
}
public final String component5() {
return this.underageMessage;
}
public final Channel component6() {
return this.safeChannel;
}
public final boolean component7() {
return this.shouldClose;
}
public final ViewState copy(boolean z2, Integer num, int i, Long l, String str, Channel channel, boolean z3) {
return new ViewState(z2, num, i, l, str, channel, z3);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ViewState)) {
return false;
}
ViewState viewState = (ViewState) obj;
return this.isSubmitting == viewState.isSubmitting && m.areEqual(this.errorStringId, viewState.errorStringId) && this.displayedChild == viewState.displayedChild && m.areEqual(this.dateOfBirth, viewState.dateOfBirth) && m.areEqual(this.underageMessage, viewState.underageMessage) && m.areEqual(this.safeChannel, viewState.safeChannel) && this.shouldClose == viewState.shouldClose;
}
public final Long getDateOfBirth() {
return this.dateOfBirth;
}
public final int getDisplayedChild() {
return this.displayedChild;
}
public final Integer getErrorStringId() {
return this.errorStringId;
}
public final Channel getSafeChannel() {
return this.safeChannel;
}
public final boolean getShouldClose() {
return this.shouldClose;
}
public final String getUnderageMessage() {
return this.underageMessage;
}
public int hashCode() {
boolean z2 = this.isSubmitting;
int i = 1;
if (z2) {
z2 = true;
}
int i2 = z2 ? 1 : 0;
int i3 = z2 ? 1 : 0;
int i4 = z2 ? 1 : 0;
int i5 = i2 * 31;
Integer num = this.errorStringId;
int i6 = 0;
int hashCode = (((i5 + (num != null ? num.hashCode() : 0)) * 31) + this.displayedChild) * 31;
Long l = this.dateOfBirth;
int hashCode2 = (hashCode + (l != null ? l.hashCode() : 0)) * 31;
String str = this.underageMessage;
int hashCode3 = (hashCode2 + (str != null ? str.hashCode() : 0)) * 31;
Channel channel = this.safeChannel;
if (channel != null) {
i6 = channel.hashCode();
}
int i7 = (hashCode3 + i6) * 31;
boolean z3 = this.shouldClose;
if (!z3) {
i = z3 ? 1 : 0;
}
return i7 + i;
}
public final boolean isSubmitting() {
return this.isSubmitting;
}
public final void setDateOfBirth(Long l) {
this.dateOfBirth = l;
}
public final void setUnderageMessage(String str) {
this.underageMessage = str;
}
public String toString() {
StringBuilder K = a.K("ViewState(isSubmitting=");
K.append(this.isSubmitting);
K.append(", errorStringId=");
K.append(this.errorStringId);
K.append(", displayedChild=");
K.append(this.displayedChild);
K.append(", dateOfBirth=");
K.append(this.dateOfBirth);
K.append(", underageMessage=");
K.append(this.underageMessage);
K.append(", safeChannel=");
K.append(this.safeChannel);
K.append(", shouldClose=");
return a.F(K, this.shouldClose, ")");
}
}
/* compiled from: WidgetAgeVerifyViewModel.kt */
public static final class Views {
public static final Views INSTANCE = new Views();
public static final int VIEW_AGE_CONFIRM = 1;
public static final int VIEW_AGE_GATED = 2;
public static final int VIEW_AGE_VERIFY = 0;
private Views() {
}
}
public WidgetAgeVerifyViewModel() {
this(null, null, null, 7, null);
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public WidgetAgeVerifyViewModel(RestAPI restAPI, StoreAuthentication storeAuthentication, Observable<StoreState> observable) {
super(new ViewState(false, null, 0, null, null, null, false));
m.checkNotNullParameter(restAPI, "restAPI");
m.checkNotNullParameter(storeAuthentication, "storeAuth");
m.checkNotNullParameter(observable, "storeObservable");
this.restAPI = restAPI;
this.storeAuth = storeAuthentication;
this.eventsSubject = PublishSubject.k0();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(observable, this, null, 2, null), WidgetAgeVerifyViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this), 62, (Object) null);
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ WidgetAgeVerifyViewModel(RestAPI restAPI, StoreAuthentication storeAuthentication, Observable observable, int i, DefaultConstructorMarker defaultConstructorMarker) {
this((i & 1) != 0 ? RestAPI.Companion.getApi() : restAPI, (i & 2) != 0 ? StoreStream.Companion.getAuthentication() : storeAuthentication, (i & 4) != 0 ? Companion.observeStores() : observable);
}
public static final /* synthetic */ void access$handleStoreState(WidgetAgeVerifyViewModel widgetAgeVerifyViewModel, StoreState storeState) {
widgetAgeVerifyViewModel.handleStoreState(storeState);
}
public static final /* synthetic */ void access$handleUserUpdateFailure(WidgetAgeVerifyViewModel widgetAgeVerifyViewModel, Error error) {
widgetAgeVerifyViewModel.handleUserUpdateFailure(error);
}
public static final /* synthetic */ void access$handleUserUpdateSuccess(WidgetAgeVerifyViewModel widgetAgeVerifyViewModel) {
widgetAgeVerifyViewModel.handleUserUpdateSuccess();
}
private final void handleStoreState(StoreState storeState) {
ViewState viewState = getViewState();
if (viewState != null) {
updateViewState(ViewState.copy$default(viewState, false, null, 0, null, null, storeState.getSafeChannel(), !storeState.getAuthed() || storeState.getNsfwAllowed() != NsfwAllowance.UNKNOWN, 31, null));
}
}
@MainThread
private final void handleUserUpdateFailure(Error error) {
ViewState viewState = getViewState();
if (viewState != null) {
Error.Response response = error.getResponse();
m.checkNotNullExpressionValue(response, "error.response");
Map<String, List<String>> messages = response.getMessages();
m.checkNotNullExpressionValue(messages, "error.response.messages");
if (messages.containsKey("date_of_birth")) {
Error.Response response2 = error.getResponse();
m.checkNotNullExpressionValue(response2, "error.response");
Map<String, List<String>> messages2 = response2.getMessages();
m.checkNotNullExpressionValue(messages2, "error.response.messages");
List<String> list = messages2.get("date_of_birth");
if (list == null) {
list = n.emptyList();
}
m.checkNotNullExpressionValue(list, "error.response.messages\n…IRTH_KEY) { emptyList() }");
String joinToString$default = u.joinToString$default(list, "\n", null, null, 0, null, null, 62, null);
updateViewState(ViewState.copy$default(viewState, false, null, 2, null, joinToString$default, null, false, 106, null));
this.storeAuth.setAgeGateError(joinToString$default);
return;
}
updateViewState(ViewState.copy$default(viewState, false, 2131886319, 0, null, null, null, false, 124, null));
}
}
@MainThread
private final void handleUserUpdateSuccess() {
ViewState viewState = getViewState();
if (viewState != null) {
updateViewState(ViewState.copy$default(viewState, false, null, 0, null, null, null, false, 126, null));
PublishSubject<Event> publishSubject = this.eventsSubject;
publishSubject.j.onNext(Event.Verified.INSTANCE);
}
}
@MainThread
public final boolean backToSafety() {
ViewState viewState = getViewState();
Channel safeChannel = viewState != null ? viewState.getSafeChannel() : null;
if (safeChannel == null) {
ChannelSelector.selectChannel$default(ChannelSelector.Companion.getInstance(), 0, 0, null, null, 12, null);
return true;
}
ChannelSelector.selectChannel$default(ChannelSelector.Companion.getInstance(), safeChannel, null, null, 6, null);
return false;
}
public final Observable<Event> observeEvents() {
PublishSubject<Event> publishSubject = this.eventsSubject;
m.checkNotNullExpressionValue(publishSubject, "eventsSubject");
return publishSubject;
}
@MainThread
public final void onConfirmBackClicked() {
ViewState viewState = getViewState();
if (viewState != null) {
updateViewState(ViewState.copy$default(viewState, false, null, 0, null, null, null, false, 123, null));
}
}
@MainThread
public final void setDateOfBirth(long j) {
ViewState viewState = getViewState();
if (viewState != null) {
updateViewState(ViewState.copy$default(viewState, false, null, 0, Long.valueOf(j), null, null, false, 119, null));
}
}
@MainThread
public final void submit(boolean z2) {
Long dateOfBirth;
ViewState viewState = getViewState();
if (viewState != null && (dateOfBirth = viewState.getDateOfBirth()) != null) {
long longValue = dateOfBirth.longValue();
boolean z3 = BirthdayHelper.INSTANCE.getAge(longValue) < 18;
if (!z2 || !z3 || viewState.getDisplayedChild() != 0) {
RestAPIParams.UserInfo userInfo = new RestAPIParams.UserInfo(null, null, null, null, null, null, null, null, null, TimeUtils.toUTCDateTime(Long.valueOf(longValue), "yyyy-MM-dd"), 511, null);
updateViewState(ViewState.copy$default(viewState, true, null, 0, null, null, null, false, 124, null));
AnalyticsTracker.INSTANCE.ageGateSubmitted(longValue, z2 ? "NSFW Channel" : "Public Server");
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(this.restAPI.patchUser(userInfo), false, 1, null), this, null, 2, null), WidgetAgeVerifyViewModel.class, (Context) null, (Function1) null, new WidgetAgeVerifyViewModel$submit$2(this), (Function0) null, (Function0) null, new WidgetAgeVerifyViewModel$submit$1(this), 54, (Object) null);
return;
}
updateViewState(ViewState.copy$default(viewState, false, null, 1, null, null, null, false, 123, null));
}
}
}