forked from Juby210/discord-jadx
340 lines
19 KiB
Java
340 lines
19 KiB
Java
package com.discord.widgets.guildscheduledevent;
|
|
|
|
import android.content.Context;
|
|
import c.d.b.a.a;
|
|
import c0.z.d.m;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.api.channel.ChannelUtils;
|
|
import com.discord.api.guildscheduledevent.GuildScheduledEvent;
|
|
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.StoreGuildScheduledEvents;
|
|
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.guildscheduledevent.WidgetPreviewGuildScheduledEvent;
|
|
import com.discord.widgets.stage.StageChannelAPI;
|
|
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 GuildScheduledEventModel eventModel;
|
|
private final WidgetPreviewGuildScheduledEvent.Companion.ExistingEventData existingEventData;
|
|
private final StoreGuildScheduledEvents guildScheduledEventsStore;
|
|
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 GuildScheduledEventModel eventModel;
|
|
private final WidgetPreviewGuildScheduledEvent.Companion.Action existingEventAction;
|
|
private final boolean isStartingEvent;
|
|
private final GuildScheduledEventLocationInfo locationInfo;
|
|
private final boolean requestProcessing;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Initialized(boolean z2, WidgetPreviewGuildScheduledEvent.Companion.Action action, boolean z3, GuildScheduledEventLocationInfo guildScheduledEventLocationInfo, GuildScheduledEventModel guildScheduledEventModel) {
|
|
super(null);
|
|
m.checkNotNullParameter(guildScheduledEventLocationInfo, "locationInfo");
|
|
m.checkNotNullParameter(guildScheduledEventModel, "eventModel");
|
|
this.requestProcessing = z2;
|
|
this.existingEventAction = action;
|
|
this.canNotifyEveryone = z3;
|
|
this.locationInfo = guildScheduledEventLocationInfo;
|
|
this.eventModel = guildScheduledEventModel;
|
|
this.isStartingEvent = action == WidgetPreviewGuildScheduledEvent.Companion.Action.START_EVENT;
|
|
}
|
|
|
|
public static /* synthetic */ Initialized copy$default(Initialized initialized, boolean z2, WidgetPreviewGuildScheduledEvent.Companion.Action action, boolean z3, GuildScheduledEventLocationInfo guildScheduledEventLocationInfo, GuildScheduledEventModel guildScheduledEventModel, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
z2 = initialized.requestProcessing;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
action = initialized.existingEventAction;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
z3 = initialized.canNotifyEveryone;
|
|
}
|
|
if ((i & 8) != 0) {
|
|
guildScheduledEventLocationInfo = initialized.locationInfo;
|
|
}
|
|
if ((i & 16) != 0) {
|
|
guildScheduledEventModel = initialized.eventModel;
|
|
}
|
|
return initialized.copy(z2, action, z3, guildScheduledEventLocationInfo, guildScheduledEventModel);
|
|
}
|
|
|
|
public final boolean component1() {
|
|
return this.requestProcessing;
|
|
}
|
|
|
|
public final WidgetPreviewGuildScheduledEvent.Companion.Action component2() {
|
|
return this.existingEventAction;
|
|
}
|
|
|
|
public final boolean component3() {
|
|
return this.canNotifyEveryone;
|
|
}
|
|
|
|
public final GuildScheduledEventLocationInfo component4() {
|
|
return this.locationInfo;
|
|
}
|
|
|
|
public final GuildScheduledEventModel component5() {
|
|
return this.eventModel;
|
|
}
|
|
|
|
public final Initialized copy(boolean z2, WidgetPreviewGuildScheduledEvent.Companion.Action action, boolean z3, GuildScheduledEventLocationInfo guildScheduledEventLocationInfo, GuildScheduledEventModel guildScheduledEventModel) {
|
|
m.checkNotNullParameter(guildScheduledEventLocationInfo, "locationInfo");
|
|
m.checkNotNullParameter(guildScheduledEventModel, "eventModel");
|
|
return new Initialized(z2, action, z3, guildScheduledEventLocationInfo, 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 && m.areEqual(this.existingEventAction, initialized.existingEventAction) && this.canNotifyEveryone == initialized.canNotifyEveryone && m.areEqual(this.locationInfo, initialized.locationInfo) && m.areEqual(this.eventModel, initialized.eventModel);
|
|
}
|
|
|
|
public final boolean getCanNotifyEveryone() {
|
|
return this.canNotifyEveryone;
|
|
}
|
|
|
|
public final GuildScheduledEventModel getEventModel() {
|
|
return this.eventModel;
|
|
}
|
|
|
|
public final WidgetPreviewGuildScheduledEvent.Companion.Action getExistingEventAction() {
|
|
return this.existingEventAction;
|
|
}
|
|
|
|
public final GuildScheduledEventLocationInfo getLocationInfo() {
|
|
return this.locationInfo;
|
|
}
|
|
|
|
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;
|
|
WidgetPreviewGuildScheduledEvent.Companion.Action action = this.existingEventAction;
|
|
int i6 = 0;
|
|
int hashCode = (i5 + (action != null ? action.hashCode() : 0)) * 31;
|
|
boolean z3 = this.canNotifyEveryone;
|
|
if (!z3) {
|
|
i = z3 ? 1 : 0;
|
|
}
|
|
int i7 = (hashCode + i) * 31;
|
|
GuildScheduledEventLocationInfo guildScheduledEventLocationInfo = this.locationInfo;
|
|
int hashCode2 = (i7 + (guildScheduledEventLocationInfo != null ? guildScheduledEventLocationInfo.hashCode() : 0)) * 31;
|
|
GuildScheduledEventModel guildScheduledEventModel = this.eventModel;
|
|
if (guildScheduledEventModel != null) {
|
|
i6 = guildScheduledEventModel.hashCode();
|
|
}
|
|
return hashCode2 + i6;
|
|
}
|
|
|
|
public final boolean isStartingEvent() {
|
|
return this.isStartingEvent;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder O = a.O("Initialized(requestProcessing=");
|
|
O.append(this.requestProcessing);
|
|
O.append(", existingEventAction=");
|
|
O.append(this.existingEventAction);
|
|
O.append(", canNotifyEveryone=");
|
|
O.append(this.canNotifyEveryone);
|
|
O.append(", locationInfo=");
|
|
O.append(this.locationInfo);
|
|
O.append(", eventModel=");
|
|
O.append(this.eventModel);
|
|
O.append(")");
|
|
return O.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.STAGE_INSTANCE.ordinal()] = 1;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public PreviewGuildScheduledEventViewModel(GuildScheduledEventModel guildScheduledEventModel, WidgetPreviewGuildScheduledEvent.Companion.ExistingEventData existingEventData, StoreChannels storeChannels, StorePermissions storePermissions, StoreGuildScheduledEvents storeGuildScheduledEvents) {
|
|
super(ViewState.Initial.INSTANCE);
|
|
m.checkNotNullParameter(guildScheduledEventModel, "eventModel");
|
|
m.checkNotNullParameter(storeChannels, "channelsStore");
|
|
m.checkNotNullParameter(storePermissions, "permissionsStore");
|
|
m.checkNotNullParameter(storeGuildScheduledEvents, "guildScheduledEventsStore");
|
|
this.eventModel = guildScheduledEventModel;
|
|
this.existingEventData = existingEventData;
|
|
this.channelsStore = storeChannels;
|
|
this.permissionsStore = storePermissions;
|
|
this.guildScheduledEventsStore = storeGuildScheduledEvents;
|
|
WidgetPreviewGuildScheduledEvent.Companion.Action action = null;
|
|
boolean z2 = (existingEventData != null ? existingEventData.getAction() : null) == WidgetPreviewGuildScheduledEvent.Companion.Action.START_EVENT;
|
|
Long channelId = guildScheduledEventModel.getChannelId();
|
|
Channel channel = channelId != null ? storeChannels.getChannel(channelId.longValue()) : null;
|
|
ViewState.Initialized initialized = new ViewState.Initialized(false, existingEventData != null ? existingEventData.getAction() : action, z2 && canNotifyEveryone(channel), GuildScheduledEventLocationInfo.Companion.buildLocationInfo(guildScheduledEventModel, 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, WidgetPreviewGuildScheduledEvent.Companion.ExistingEventData existingEventData, StoreChannels storeChannels, StorePermissions storePermissions, StoreGuildScheduledEvents storeGuildScheduledEvents, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(guildScheduledEventModel, existingEventData, (i & 4) != 0 ? StoreStream.Companion.getChannels() : storeChannels, (i & 8) != 0 ? StoreStream.Companion.getPermissions() : storePermissions, (i & 16) != 0 ? StoreStream.Companion.getGuildScheduledEvents() : storeGuildScheduledEvents);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setRequestFinished(PreviewGuildScheduledEventViewModel previewGuildScheduledEventViewModel) {
|
|
previewGuildScheduledEventViewModel.setRequestFinished();
|
|
}
|
|
|
|
private final boolean canNotifyEveryone(Channel channel) {
|
|
Long l;
|
|
if (channel == null || !ChannelUtils.z(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, Function1<? super Long, Unit> function1) {
|
|
RestAPIParams.CreateGuildScheduledEventBody createRequestBody = this.eventModel.toCreateRequestBody();
|
|
if (createRequestBody != null) {
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().createGuildScheduledEvent(this.eventModel.getGuildId(), createRequestBody), 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, function1), 52, (Object) null);
|
|
}
|
|
}
|
|
|
|
private final void editEvent(Context context, Function1<? super Long, Unit> function1) {
|
|
long guildScheduledEventId;
|
|
GuildScheduledEvent findEventFromStore;
|
|
RestAPIParams.UpdateGuildScheduledEventBody updateRequestBody;
|
|
WidgetPreviewGuildScheduledEvent.Companion.ExistingEventData existingEventData = this.existingEventData;
|
|
if (existingEventData != null && (findEventFromStore = this.guildScheduledEventsStore.findEventFromStore((guildScheduledEventId = existingEventData.getGuildScheduledEventId()), Long.valueOf(this.eventModel.getGuildId()))) != null && (updateRequestBody = this.eventModel.toUpdateRequestBody(findEventFromStore)) != null) {
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().updateGuildScheduledEvent(guildScheduledEventId, updateRequestBody), false, 1, null), this, null, 2, null), PreviewGuildScheduledEventViewModel.class, context, (Function1) null, new PreviewGuildScheduledEventViewModel$editEvent$1(this), (Function0) null, (Function0) null, new PreviewGuildScheduledEventViewModel$editEvent$2(this, function1, guildScheduledEventId), 52, (Object) null);
|
|
}
|
|
}
|
|
|
|
public static /* synthetic */ void onBottomButtonClicked$default(PreviewGuildScheduledEventViewModel previewGuildScheduledEventViewModel, Context context, boolean z2, Function1 function1, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
z2 = false;
|
|
}
|
|
previewGuildScheduledEventViewModel.onBottomButtonClicked(context, z2, function1);
|
|
}
|
|
|
|
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, null, false, null, null, 30, null));
|
|
}
|
|
|
|
private final void startEvent(Context context, Function1<? super Long, Unit> function1) {
|
|
WidgetPreviewGuildScheduledEvent.Companion.ExistingEventData existingEventData = this.existingEventData;
|
|
if (existingEventData != null) {
|
|
long guildScheduledEventId = existingEventData.getGuildScheduledEventId();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(GuildScheduledEventAPI.INSTANCE.startEvent(guildScheduledEventId), false, 1, null), this, null, 2, null), PreviewGuildScheduledEventViewModel.class, context, (Function1) null, new PreviewGuildScheduledEventViewModel$startEvent$1(this), (Function0) null, (Function0) null, new PreviewGuildScheduledEventViewModel$startEvent$2(this, function1, guildScheduledEventId), 52, (Object) null);
|
|
}
|
|
}
|
|
|
|
private final void startStageEvent(Context context, boolean z2, Function1<? super Long, Unit> function1) {
|
|
if (this.eventModel.getName() != null && this.eventModel.getChannelId() != null) {
|
|
WidgetPreviewGuildScheduledEvent.Companion.ExistingEventData existingEventData = this.existingEventData;
|
|
Long valueOf = existingEventData != null ? Long.valueOf(existingEventData.getGuildScheduledEventId()) : 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(valueOf)), 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, function1, valueOf), 52, (Object) null);
|
|
}
|
|
}
|
|
|
|
public final ViewState getCurrentViewState() {
|
|
return this.currentViewState;
|
|
}
|
|
|
|
public final boolean isCreate() {
|
|
return this.existingEventData == null;
|
|
}
|
|
|
|
public final void onBottomButtonClicked(Context context, boolean z2, Function1<? super Long, Unit> function1) {
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(function1, "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, null, false, null, null, 30, null));
|
|
WidgetPreviewGuildScheduledEvent.Companion.ExistingEventData existingEventData = this.existingEventData;
|
|
if (existingEventData == null) {
|
|
createEvent(context, function1);
|
|
} else if (existingEventData.getAction() == WidgetPreviewGuildScheduledEvent.Companion.Action.EDIT_EVENT) {
|
|
editEvent(context, function1);
|
|
} else if (this.eventModel.getEntityType().ordinal() != 1) {
|
|
startEvent(context, function1);
|
|
} else {
|
|
startStageEvent(context, z2, function1);
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void setCurrentViewState(ViewState viewState) {
|
|
m.checkNotNullParameter(viewState, "<set-?>");
|
|
this.currentViewState = viewState;
|
|
}
|
|
}
|