discord-jadx/app/src/main/java/com/discord/widgets/guildscheduledevent/PreviewGuildScheduledEventV...

315 lines
15 KiB
Java

package com.discord.widgets.guildscheduledevent;
import android.content.Context;
import c.d.b.a.a;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.api.channel.Channel;
import com.discord.api.guildscheduledevent.GuildScheduledEventEntityType;
import com.discord.api.permission.Permission;
import com.discord.api.stageinstance.StageInstancePrivacyLevel;
import com.discord.app.AppViewModel;
import com.discord.restapi.RestAPIParams;
import com.discord.stores.StoreChannels;
import com.discord.stores.StorePermissions;
import com.discord.stores.StoreStream;
import com.discord.utilities.permissions.PermissionUtils;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.widgets.stage.StageChannelAPI;
import d0.z.d.m;
import java.util.Objects;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: PreviewGuildScheduledEventViewModel.kt */
public final class PreviewGuildScheduledEventViewModel extends AppViewModel<ViewState> {
private final StoreChannels channelsStore;
private ViewState currentViewState;
private final Long eventId;
private final GuildScheduledEventModel eventModel;
private final StorePermissions permissionsStore;
/* compiled from: PreviewGuildScheduledEventViewModel.kt */
public static abstract class ViewState {
/* compiled from: PreviewGuildScheduledEventViewModel.kt */
public static final class Initial extends ViewState {
public static final Initial INSTANCE = new Initial();
private Initial() {
super(null);
}
}
/* compiled from: PreviewGuildScheduledEventViewModel.kt */
public static final class Initialized extends ViewState {
private final boolean canNotifyEveryone;
private final Channel channel;
private final boolean eventAlreadyExists;
private final GuildScheduledEventModel eventModel;
private final boolean requestProcessing;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Initialized(boolean z2, boolean z3, boolean z4, Channel channel, GuildScheduledEventModel guildScheduledEventModel) {
super(null);
m.checkNotNullParameter(guildScheduledEventModel, "eventModel");
this.requestProcessing = z2;
this.eventAlreadyExists = z3;
this.canNotifyEveryone = z4;
this.channel = channel;
this.eventModel = guildScheduledEventModel;
}
public static /* synthetic */ Initialized copy$default(Initialized initialized, boolean z2, boolean z3, boolean z4, Channel channel, GuildScheduledEventModel guildScheduledEventModel, int i, Object obj) {
if ((i & 1) != 0) {
z2 = initialized.requestProcessing;
}
if ((i & 2) != 0) {
z3 = initialized.eventAlreadyExists;
}
if ((i & 4) != 0) {
z4 = initialized.canNotifyEveryone;
}
if ((i & 8) != 0) {
channel = initialized.channel;
}
if ((i & 16) != 0) {
guildScheduledEventModel = initialized.eventModel;
}
return initialized.copy(z2, z3, z4, channel, guildScheduledEventModel);
}
public final boolean component1() {
return this.requestProcessing;
}
public final boolean component2() {
return this.eventAlreadyExists;
}
public final boolean component3() {
return this.canNotifyEveryone;
}
public final Channel component4() {
return this.channel;
}
public final GuildScheduledEventModel component5() {
return this.eventModel;
}
public final Initialized copy(boolean z2, boolean z3, boolean z4, Channel channel, GuildScheduledEventModel guildScheduledEventModel) {
m.checkNotNullParameter(guildScheduledEventModel, "eventModel");
return new Initialized(z2, z3, z4, channel, guildScheduledEventModel);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Initialized)) {
return false;
}
Initialized initialized = (Initialized) obj;
return this.requestProcessing == initialized.requestProcessing && this.eventAlreadyExists == initialized.eventAlreadyExists && this.canNotifyEveryone == initialized.canNotifyEveryone && m.areEqual(this.channel, initialized.channel) && m.areEqual(this.eventModel, initialized.eventModel);
}
public final boolean getCanNotifyEveryone() {
return this.canNotifyEveryone;
}
public final Channel getChannel() {
return this.channel;
}
public final boolean getEventAlreadyExists() {
return this.eventAlreadyExists;
}
public final GuildScheduledEventModel getEventModel() {
return this.eventModel;
}
public final boolean getRequestProcessing() {
return this.requestProcessing;
}
public int hashCode() {
boolean z2 = this.requestProcessing;
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;
boolean z3 = this.eventAlreadyExists;
if (z3) {
z3 = true;
}
int i6 = z3 ? 1 : 0;
int i7 = z3 ? 1 : 0;
int i8 = z3 ? 1 : 0;
int i9 = (i5 + i6) * 31;
boolean z4 = this.canNotifyEveryone;
if (!z4) {
i = z4 ? 1 : 0;
}
int i10 = (i9 + i) * 31;
Channel channel = this.channel;
int i11 = 0;
int hashCode = (i10 + (channel != null ? channel.hashCode() : 0)) * 31;
GuildScheduledEventModel guildScheduledEventModel = this.eventModel;
if (guildScheduledEventModel != null) {
i11 = guildScheduledEventModel.hashCode();
}
return hashCode + i11;
}
public String toString() {
StringBuilder P = a.P("Initialized(requestProcessing=");
P.append(this.requestProcessing);
P.append(", eventAlreadyExists=");
P.append(this.eventAlreadyExists);
P.append(", canNotifyEveryone=");
P.append(this.canNotifyEveryone);
P.append(", channel=");
P.append(this.channel);
P.append(", eventModel=");
P.append(this.eventModel);
P.append(")");
return P.toString();
}
}
/* compiled from: PreviewGuildScheduledEventViewModel.kt */
public static final class Invalid extends ViewState {
public static final Invalid INSTANCE = new Invalid();
private Invalid() {
super(null);
}
}
private ViewState() {
}
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
public final /* synthetic */ class WhenMappings {
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
static {
GuildScheduledEventEntityType.values();
int[] iArr = new int[5];
$EnumSwitchMapping$0 = iArr;
iArr[GuildScheduledEventEntityType.VOICE.ordinal()] = 1;
iArr[GuildScheduledEventEntityType.STAGE_INSTANCE.ordinal()] = 2;
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public PreviewGuildScheduledEventViewModel(GuildScheduledEventModel guildScheduledEventModel, Long l, StoreChannels storeChannels, StorePermissions storePermissions) {
super(ViewState.Initial.INSTANCE);
m.checkNotNullParameter(guildScheduledEventModel, "eventModel");
m.checkNotNullParameter(storeChannels, "channelsStore");
m.checkNotNullParameter(storePermissions, "permissionsStore");
this.eventModel = guildScheduledEventModel;
this.eventId = l;
this.channelsStore = storeChannels;
this.permissionsStore = storePermissions;
boolean z2 = l != null;
Long channelId = guildScheduledEventModel.getChannelId();
Channel channel = channelId != null ? storeChannels.getChannel(channelId.longValue()) : null;
ViewState.Initialized initialized = new ViewState.Initialized(false, z2, z2 && canNotifyEveryone(channel), channel, guildScheduledEventModel);
this.currentViewState = initialized;
updateViewState(initialized);
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ PreviewGuildScheduledEventViewModel(GuildScheduledEventModel guildScheduledEventModel, Long l, StoreChannels storeChannels, StorePermissions storePermissions, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(guildScheduledEventModel, l, (i & 4) != 0 ? StoreStream.Companion.getChannels() : storeChannels, (i & 8) != 0 ? StoreStream.Companion.getPermissions() : storePermissions);
}
public static final /* synthetic */ void access$setRequestFinished(PreviewGuildScheduledEventViewModel previewGuildScheduledEventViewModel) {
previewGuildScheduledEventViewModel.setRequestFinished();
}
private final boolean canNotifyEveryone(Channel channel) {
Long l;
if (channel == null || !AnimatableValueParser.x1(channel) || (l = (Long) a.c(channel, this.permissionsStore.getPermissionsByChannel())) == null) {
return false;
}
return PermissionUtils.can(Permission.MENTION_EVERYONE, Long.valueOf(l.longValue()));
}
private final void createEvent(Context context, Function0<Unit> function0) {
RestAPIParams.CreateGuildScheduledEventBody requestBody = this.eventModel.toRequestBody();
if (requestBody != null) {
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().createGuildScheduledEvent(this.eventModel.getGuildId(), requestBody), false, 1, null), this, null, 2, null), PreviewGuildScheduledEventViewModel.class, context, (Function1) null, new PreviewGuildScheduledEventViewModel$createEvent$1(this), (Function0) null, (Function0) null, new PreviewGuildScheduledEventViewModel$createEvent$2(this, function0), 52, (Object) null);
}
}
public static /* synthetic */ void onBottomButtonClicked$default(PreviewGuildScheduledEventViewModel previewGuildScheduledEventViewModel, Context context, boolean z2, Function0 function0, int i, Object obj) {
if ((i & 2) != 0) {
z2 = false;
}
previewGuildScheduledEventViewModel.onBottomButtonClicked(context, z2, function0);
}
private final void setRequestFinished() {
ViewState requireViewState = requireViewState();
Objects.requireNonNull(requireViewState, "null cannot be cast to non-null type com.discord.widgets.guildscheduledevent.PreviewGuildScheduledEventViewModel.ViewState.Initialized");
updateViewState(ViewState.Initialized.copy$default((ViewState.Initialized) requireViewState, false, false, false, null, null, 30, null));
}
private final void startStageEvent(Context context, boolean z2, Function0<Unit> function0) {
if (this.eventModel.getName() != null && this.eventModel.getChannelId() != null) {
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(StageChannelAPI.INSTANCE.startStageInstance(this.eventModel.getChannelId().longValue(), this.eventModel.getName(), StageInstancePrivacyLevel.GUILD_ONLY, z2, String.valueOf(this.eventId)), false, 1, null), this, null, 2, null), PreviewGuildScheduledEventViewModel.class, context, (Function1) null, new PreviewGuildScheduledEventViewModel$startStageEvent$1(this), (Function0) null, (Function0) null, new PreviewGuildScheduledEventViewModel$startStageEvent$2(this, function0), 52, (Object) null);
}
}
private final void startVoiceEvent(Context context, Function0<Unit> function0) {
Long l = this.eventId;
if (l != null) {
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(GuildScheduledEventAPI.INSTANCE.startEvent(l.longValue()), false, 1, null), this, null, 2, null), PreviewGuildScheduledEventViewModel.class, context, (Function1) null, new PreviewGuildScheduledEventViewModel$startVoiceEvent$1(this), (Function0) null, (Function0) null, new PreviewGuildScheduledEventViewModel$startVoiceEvent$2(this, function0), 52, (Object) null);
}
}
public final ViewState getCurrentViewState() {
return this.currentViewState;
}
public final void onBottomButtonClicked(Context context, boolean z2, Function0<Unit> function0) {
m.checkNotNullParameter(context, "context");
m.checkNotNullParameter(function0, "onRequestSuccess");
ViewState viewState = this.currentViewState;
Objects.requireNonNull(viewState, "null cannot be cast to non-null type com.discord.widgets.guildscheduledevent.PreviewGuildScheduledEventViewModel.ViewState.Initialized");
ViewState.Initialized initialized = (ViewState.Initialized) viewState;
if (!initialized.getRequestProcessing()) {
updateViewState(ViewState.Initialized.copy$default(initialized, true, false, false, null, null, 30, null));
if (!initialized.getEventAlreadyExists()) {
createEvent(context, function0);
return;
}
int ordinal = this.eventModel.getEntityType().ordinal();
if (ordinal == 1) {
startStageEvent(context, z2, function0);
} else if (ordinal == 2) {
startVoiceEvent(context, function0);
}
}
}
public final void setCurrentViewState(ViewState viewState) {
m.checkNotNullParameter(viewState, "<set-?>");
this.currentViewState = viewState;
}
}