392 lines
15 KiB
Java
392 lines
15 KiB
Java
package com.discord.widgets.guilds.leave;
|
|
|
|
import android.content.Context;
|
|
import androidx.annotation.MainThread;
|
|
import c.d.b.a.a;
|
|
import com.discord.app.AppViewModel;
|
|
import com.discord.models.guild.Guild;
|
|
import com.discord.stores.StoreGuilds;
|
|
import com.discord.stores.StoreLurking;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import d0.z.d.k;
|
|
import d0.z.d.m;
|
|
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: LeaveGuildDialogViewModel.kt */
|
|
public final class LeaveGuildDialogViewModel extends AppViewModel<ViewState> {
|
|
public static final Companion Companion = new Companion(null);
|
|
private final PublishSubject<Event> eventSubject;
|
|
private final long guildId;
|
|
private final StoreLurking lurkingStore;
|
|
private final RestAPI restAPI;
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
/* renamed from: com.discord.widgets.guilds.leave.LeaveGuildDialogViewModel$1 reason: invalid class name */
|
|
public static final /* synthetic */ class AnonymousClass1 extends k implements Function1<StoreState, Unit> {
|
|
public AnonymousClass1(LeaveGuildDialogViewModel leaveGuildDialogViewModel) {
|
|
super(1, leaveGuildDialogViewModel, LeaveGuildDialogViewModel.class, "handleStoreState", "handleStoreState(Lcom/discord/widgets/guilds/leave/LeaveGuildDialogViewModel$StoreState;)V", 0);
|
|
}
|
|
|
|
/* 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, "p1");
|
|
LeaveGuildDialogViewModel.access$handleStoreState((LeaveGuildDialogViewModel) this.receiver, storeState);
|
|
}
|
|
}
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public static final /* synthetic */ Observable access$observeStoreState(Companion companion, long j, StoreGuilds storeGuilds, StoreLurking storeLurking) {
|
|
return companion.observeStoreState(j, storeGuilds, storeLurking);
|
|
}
|
|
|
|
private final Observable<StoreState> observeStoreState(long j, StoreGuilds storeGuilds, StoreLurking storeLurking) {
|
|
Observable<StoreState> j2 = Observable.j(storeGuilds.observeGuild(j), storeLurking.isLurkingObs(j), LeaveGuildDialogViewModel$Companion$observeStoreState$1.INSTANCE);
|
|
m.checkNotNullExpressionValue(j2, "Observable.combineLatest…urking)\n }\n }");
|
|
return j2;
|
|
}
|
|
}
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
public static abstract class Event {
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
public static final class Dismiss extends Event {
|
|
public static final Dismiss INSTANCE = new Dismiss();
|
|
|
|
private Dismiss() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
private Event() {
|
|
}
|
|
|
|
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
public static abstract class StoreState {
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
public static final class Invalid extends StoreState {
|
|
public static final Invalid INSTANCE = new Invalid();
|
|
|
|
private Invalid() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
public static final class Valid extends StoreState {
|
|
private final Guild guild;
|
|
private final boolean isLurking;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Valid(Guild guild, boolean z2) {
|
|
super(null);
|
|
m.checkNotNullParameter(guild, "guild");
|
|
this.guild = guild;
|
|
this.isLurking = z2;
|
|
}
|
|
|
|
public static /* synthetic */ Valid copy$default(Valid valid, Guild guild, boolean z2, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
guild = valid.guild;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
z2 = valid.isLurking;
|
|
}
|
|
return valid.copy(guild, z2);
|
|
}
|
|
|
|
public final Guild component1() {
|
|
return this.guild;
|
|
}
|
|
|
|
public final boolean component2() {
|
|
return this.isLurking;
|
|
}
|
|
|
|
public final Valid copy(Guild guild, boolean z2) {
|
|
m.checkNotNullParameter(guild, "guild");
|
|
return new Valid(guild, z2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof Valid)) {
|
|
return false;
|
|
}
|
|
Valid valid = (Valid) obj;
|
|
return m.areEqual(this.guild, valid.guild) && this.isLurking == valid.isLurking;
|
|
}
|
|
|
|
public final Guild getGuild() {
|
|
return this.guild;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Guild guild = this.guild;
|
|
int hashCode = (guild != null ? guild.hashCode() : 0) * 31;
|
|
boolean z2 = this.isLurking;
|
|
if (z2) {
|
|
z2 = true;
|
|
}
|
|
int i = z2 ? 1 : 0;
|
|
int i2 = z2 ? 1 : 0;
|
|
int i3 = z2 ? 1 : 0;
|
|
return hashCode + i;
|
|
}
|
|
|
|
public final boolean isLurking() {
|
|
return this.isLurking;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("Valid(guild=");
|
|
L.append(this.guild);
|
|
L.append(", isLurking=");
|
|
return a.G(L, this.isLurking, ")");
|
|
}
|
|
}
|
|
|
|
private StoreState() {
|
|
}
|
|
|
|
public /* synthetic */ StoreState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
public static abstract class ViewState {
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
public static final class Invalid extends ViewState {
|
|
public static final Invalid INSTANCE = new Invalid();
|
|
|
|
private Invalid() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: LeaveGuildDialogViewModel.kt */
|
|
public static final class Valid extends ViewState {
|
|
private final Guild guild;
|
|
private final boolean isLoading;
|
|
private final boolean isLurking;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Valid(Guild guild, boolean z2, boolean z3) {
|
|
super(null);
|
|
m.checkNotNullParameter(guild, "guild");
|
|
this.guild = guild;
|
|
this.isLoading = z2;
|
|
this.isLurking = z3;
|
|
}
|
|
|
|
public static /* synthetic */ Valid copy$default(Valid valid, Guild guild, boolean z2, boolean z3, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
guild = valid.guild;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
z2 = valid.isLoading;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
z3 = valid.isLurking;
|
|
}
|
|
return valid.copy(guild, z2, z3);
|
|
}
|
|
|
|
public final Guild component1() {
|
|
return this.guild;
|
|
}
|
|
|
|
public final boolean component2() {
|
|
return this.isLoading;
|
|
}
|
|
|
|
public final boolean component3() {
|
|
return this.isLurking;
|
|
}
|
|
|
|
public final Valid copy(Guild guild, boolean z2, boolean z3) {
|
|
m.checkNotNullParameter(guild, "guild");
|
|
return new Valid(guild, z2, z3);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof Valid)) {
|
|
return false;
|
|
}
|
|
Valid valid = (Valid) obj;
|
|
return m.areEqual(this.guild, valid.guild) && this.isLoading == valid.isLoading && this.isLurking == valid.isLurking;
|
|
}
|
|
|
|
public final Guild getGuild() {
|
|
return this.guild;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Guild guild = this.guild;
|
|
int hashCode = (guild != null ? guild.hashCode() : 0) * 31;
|
|
boolean z2 = this.isLoading;
|
|
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.isLurking;
|
|
if (!z3) {
|
|
i = z3 ? 1 : 0;
|
|
}
|
|
return i5 + i;
|
|
}
|
|
|
|
public final boolean isLoading() {
|
|
return this.isLoading;
|
|
}
|
|
|
|
public final boolean isLurking() {
|
|
return this.isLurking;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("Valid(guild=");
|
|
L.append(this.guild);
|
|
L.append(", isLoading=");
|
|
L.append(this.isLoading);
|
|
L.append(", isLurking=");
|
|
return a.G(L, this.isLurking, ")");
|
|
}
|
|
}
|
|
|
|
private ViewState() {
|
|
}
|
|
|
|
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public LeaveGuildDialogViewModel(long j, RestAPI restAPI, StoreLurking storeLurking, Observable<StoreState> observable) {
|
|
super(null);
|
|
m.checkNotNullParameter(restAPI, "restAPI");
|
|
m.checkNotNullParameter(storeLurking, "lurkingStore");
|
|
m.checkNotNullParameter(observable, "storeStateObservable");
|
|
this.guildId = j;
|
|
this.restAPI = restAPI;
|
|
this.lurkingStore = storeLurking;
|
|
this.eventSubject = PublishSubject.k0();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(observable, this, null, 2, null), LeaveGuildDialogViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this), 62, (Object) null);
|
|
}
|
|
|
|
/* JADX WARNING: Illegal instructions before constructor call */
|
|
public /* synthetic */ LeaveGuildDialogViewModel(long j, RestAPI restAPI, StoreLurking storeLurking, Observable observable, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(j, restAPI, storeLurking, (i & 8) != 0 ? Companion.access$observeStoreState(Companion, j, StoreStream.Companion.getGuilds(), storeLurking) : observable);
|
|
restAPI = (i & 2) != 0 ? RestAPI.Companion.getApi() : restAPI;
|
|
storeLurking = (i & 4) != 0 ? StoreStream.Companion.getLurking() : storeLurking;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleStoreState(LeaveGuildDialogViewModel leaveGuildDialogViewModel, StoreState storeState) {
|
|
leaveGuildDialogViewModel.handleStoreState(storeState);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$onLeaveFailed(LeaveGuildDialogViewModel leaveGuildDialogViewModel) {
|
|
leaveGuildDialogViewModel.onLeaveFailed();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$onLeaveSucceeded(LeaveGuildDialogViewModel leaveGuildDialogViewModel) {
|
|
leaveGuildDialogViewModel.onLeaveSucceeded();
|
|
}
|
|
|
|
@MainThread
|
|
private final void handleStoreState(StoreState storeState) {
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
boolean isLoading = valid != null ? valid.isLoading() : false;
|
|
if (storeState instanceof StoreState.Valid) {
|
|
StoreState.Valid valid2 = (StoreState.Valid) storeState;
|
|
updateViewState(new ViewState.Valid(valid2.getGuild(), isLoading, valid2.isLurking()));
|
|
} else if (m.areEqual(storeState, StoreState.Invalid.INSTANCE)) {
|
|
updateViewState(ViewState.Invalid.INSTANCE);
|
|
}
|
|
}
|
|
|
|
@MainThread
|
|
private final void onLeaveFailed() {
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null) {
|
|
updateViewState(ViewState.Valid.copy$default(valid, null, false, false, 5, null));
|
|
}
|
|
}
|
|
|
|
@MainThread
|
|
private final void onLeaveSucceeded() {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
publishSubject.j.onNext(Event.Dismiss.INSTANCE);
|
|
}
|
|
|
|
@MainThread
|
|
public final void leaveGuild() {
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null) {
|
|
updateViewState(ViewState.Valid.copy$default(valid, null, true, false, 5, null));
|
|
if (valid.isLurking()) {
|
|
this.lurkingStore.stopLurking(valid.getGuild().getId(), new LeaveGuildDialogViewModel$leaveGuild$1(this), new LeaveGuildDialogViewModel$leaveGuild$2(this));
|
|
return;
|
|
}
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(this.restAPI.leaveGuild(this.guildId), false, 1, null), this, null, 2, null), LeaveGuildDialogViewModel.class, (Context) null, (Function1) null, new LeaveGuildDialogViewModel$leaveGuild$4(this), (Function0) null, (Function0) null, new LeaveGuildDialogViewModel$leaveGuild$3(this), 54, (Object) null);
|
|
}
|
|
}
|
|
|
|
public final Observable<Event> observeEvents() {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
|
|
return publishSubject;
|
|
}
|
|
}
|