214 lines
11 KiB
Java
214 lines
11 KiB
Java
package com.discord.utilities.guildscheduledevent;
|
|
|
|
import c.d.b.a.a;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.api.guildscheduledevent.GuildScheduledEvent;
|
|
import com.discord.api.permission.Permission;
|
|
import com.discord.api.role.GuildRole;
|
|
import com.discord.models.guild.Guild;
|
|
import com.discord.models.member.GuildMember;
|
|
import com.discord.stores.StoreChannels;
|
|
import com.discord.stores.StoreGuilds;
|
|
import com.discord.stores.StorePermissions;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreUser;
|
|
import com.discord.stores.StoreVoiceParticipants;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import com.discord.stores.updates.ObservationDeckProvider;
|
|
import com.discord.utilities.permissions.PermissionUtils;
|
|
import com.discord.widgets.voice.model.CallModel;
|
|
import d0.t.h0;
|
|
import d0.z.d.m;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
/* compiled from: GuildScheduledEventUtilities.kt */
|
|
public final class GuildScheduledEventUtilities {
|
|
public static final String ANALYTICS_SOURCE = "Guild Events";
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final String QUERY_PARAM_NAME = "event";
|
|
|
|
/* compiled from: GuildScheduledEventUtilities.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public static /* synthetic */ boolean canCreateAnyEvent$default(Companion companion, long j, StoreChannels storeChannels, StorePermissions storePermissions, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
storeChannels = StoreStream.Companion.getChannels();
|
|
}
|
|
if ((i & 4) != 0) {
|
|
storePermissions = StoreStream.Companion.getPermissions();
|
|
}
|
|
return companion.canCreateAnyEvent(j, storeChannels, storePermissions);
|
|
}
|
|
|
|
public static /* synthetic */ boolean canShareEvent$default(Companion companion, Long l, StoreChannels storeChannels, StoreGuilds storeGuilds, StoreUser storeUser, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
storeChannels = StoreStream.Companion.getChannels();
|
|
}
|
|
if ((i & 4) != 0) {
|
|
storeGuilds = StoreStream.Companion.getGuilds();
|
|
}
|
|
if ((i & 8) != 0) {
|
|
storeUser = StoreStream.Companion.getUsers();
|
|
}
|
|
return companion.canShareEvent(l, storeChannels, storeGuilds, storeUser);
|
|
}
|
|
|
|
public static /* synthetic */ boolean canStartEvent$default(Companion companion, Long l, StoreChannels storeChannels, StorePermissions storePermissions, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
storeChannels = StoreStream.Companion.getChannels();
|
|
}
|
|
if ((i & 4) != 0) {
|
|
storePermissions = StoreStream.Companion.getPermissions();
|
|
}
|
|
return companion.canStartEvent(l, storeChannels, storePermissions);
|
|
}
|
|
|
|
public static /* synthetic */ List getGuildScheduledEventCreatableChannelsForGuild$default(Companion companion, long j, StoreChannels storeChannels, StorePermissions storePermissions, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
storeChannels = StoreStream.Companion.getChannels();
|
|
}
|
|
if ((i & 4) != 0) {
|
|
storePermissions = StoreStream.Companion.getPermissions();
|
|
}
|
|
return companion.getGuildScheduledEventCreatableChannelsForGuild(j, storeChannels, storePermissions);
|
|
}
|
|
|
|
public static /* synthetic */ GuildScheduledEvent getGuildScheduledEventToEndForCall$default(Companion companion, CallModel callModel, Long l, StoreGuilds storeGuilds, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
storeGuilds = StoreStream.Companion.getGuilds();
|
|
}
|
|
return companion.getGuildScheduledEventToEndForCall(callModel, l, storeGuilds);
|
|
}
|
|
|
|
public static /* synthetic */ Observable observeGuildScheduledEventCreatableChannelsForGuild$default(Companion companion, long j, ObservationDeck observationDeck, StoreChannels storeChannels, StorePermissions storePermissions, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
observationDeck = ObservationDeckProvider.get();
|
|
}
|
|
if ((i & 4) != 0) {
|
|
storeChannels = StoreStream.Companion.getChannels();
|
|
}
|
|
if ((i & 8) != 0) {
|
|
storePermissions = StoreStream.Companion.getPermissions();
|
|
}
|
|
return companion.observeGuildScheduledEventCreatableChannelsForGuild(j, observationDeck, storeChannels, storePermissions);
|
|
}
|
|
|
|
public final boolean canCreateAnyEvent(long j, StoreChannels storeChannels, StorePermissions storePermissions) {
|
|
m.checkNotNullParameter(storeChannels, "channelsStore");
|
|
m.checkNotNullParameter(storePermissions, "permissionsStore");
|
|
Long l = storePermissions.getGuildPermissions().get(Long.valueOf(j));
|
|
if (l == null) {
|
|
return false;
|
|
}
|
|
if (PermissionUtils.can(Permission.MANAGE_EVENTS, Long.valueOf(l.longValue()))) {
|
|
return true;
|
|
}
|
|
return !getGuildScheduledEventCreatableChannelsForGuild(j, storeChannels, storePermissions).isEmpty();
|
|
}
|
|
|
|
public final boolean canCreateExternalEvent(Long l) {
|
|
return PermissionUtils.can(Permission.MANAGE_EVENTS, l);
|
|
}
|
|
|
|
public final boolean canShareEvent(Long l, StoreChannels storeChannels, StoreGuilds storeGuilds, StoreUser storeUser) {
|
|
GuildMember member;
|
|
m.checkNotNullParameter(storeChannels, "channelsStore");
|
|
m.checkNotNullParameter(storeGuilds, "guildsStore");
|
|
m.checkNotNullParameter(storeUser, "usersStore");
|
|
if (l == null) {
|
|
return true;
|
|
}
|
|
Channel channel = storeChannels.getChannel(l.longValue());
|
|
if (channel != null) {
|
|
PermissionUtils permissionUtils = PermissionUtils.INSTANCE;
|
|
Map<Long, GuildRole> map = (Map) a.t0(channel, storeGuilds.getRoles());
|
|
if (map == null) {
|
|
map = h0.emptyMap();
|
|
}
|
|
return permissionUtils.canEveryoneRole(1025, channel, map) && (member = storeGuilds.getMember(channel.f(), storeUser.getMe().getId())) != null && !member.getPending();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public final boolean canStartEvent(Long l, StoreChannels storeChannels, StorePermissions storePermissions) {
|
|
m.checkNotNullParameter(storeChannels, "channelsStore");
|
|
m.checkNotNullParameter(storePermissions, "permissionsStore");
|
|
if (l == null) {
|
|
return false;
|
|
}
|
|
Channel channel = storeChannels.getChannel(l.longValue());
|
|
Long l2 = storePermissions.getPermissionsByChannel().get(l);
|
|
if (channel == null) {
|
|
return false;
|
|
}
|
|
return canStartEventInChannel(channel, l2);
|
|
}
|
|
|
|
public final boolean canStartEventInChannel(Channel channel, Long l) {
|
|
m.checkNotNullParameter(channel, "channel");
|
|
if (!PermissionUtils.can(8589935616L, l)) {
|
|
return false;
|
|
}
|
|
if (AnimatableValueParser.x1(channel)) {
|
|
return PermissionUtils.can(Permission.START_STAGE_EVENT, l);
|
|
}
|
|
if (AnimatableValueParser.D1(channel)) {
|
|
return PermissionUtils.can(Permission.START_VOICE_EVENT, l);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public final List<Channel> getGuildScheduledEventCreatableChannelsForGuild(long j, StoreChannels storeChannels, StorePermissions storePermissions) {
|
|
m.checkNotNullParameter(storeChannels, "channelsStore");
|
|
m.checkNotNullParameter(storePermissions, "permissionsStore");
|
|
Map<Long, Channel> channelsForGuild = storeChannels.getChannelsForGuild(j);
|
|
Map<Long, Long> permissionsByChannel = storePermissions.getPermissionsByChannel();
|
|
Collection<Channel> values = channelsForGuild.values();
|
|
ArrayList arrayList = new ArrayList();
|
|
for (Object obj : values) {
|
|
Channel channel = (Channel) obj;
|
|
if (GuildScheduledEventUtilities.Companion.canStartEventInChannel(channel, (Long) a.c(channel, permissionsByChannel))) {
|
|
arrayList.add(obj);
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
public final GuildScheduledEvent getGuildScheduledEventToEndForCall(CallModel callModel, Long l, StoreGuilds storeGuilds) {
|
|
GuildScheduledEvent liveEvent;
|
|
m.checkNotNullParameter(callModel, "callModel");
|
|
m.checkNotNullParameter(storeGuilds, "guildsStore");
|
|
Channel channel = callModel.getChannel();
|
|
Guild guild = storeGuilds.getGuild(channel.f());
|
|
if (guild == null || (liveEvent = GuildScheduledEventUtilitiesKt.getLiveEvent(callModel.getGuildScheduledEvents())) == null || !canStartEventInChannel(channel, l)) {
|
|
return null;
|
|
}
|
|
Map map = (Map) a.d(guild, storeGuilds.getRoles());
|
|
for (Map.Entry<Long, StoreVoiceParticipants.VoiceUser> entry : callModel.getParticipants().entrySet()) {
|
|
long longValue = entry.getKey().longValue();
|
|
if (!entry.getValue().isMe() && !canStartEventInChannel(channel, Long.valueOf(PermissionUtils.computeNonThreadPermissions(longValue, guild.getId(), guild.getOwnerId(), entry.getValue().getGuildMember(), map, channel.s())))) {
|
|
return null;
|
|
}
|
|
}
|
|
return liveEvent;
|
|
}
|
|
|
|
public final Observable<List<Channel>> observeGuildScheduledEventCreatableChannelsForGuild(long j, ObservationDeck observationDeck, StoreChannels storeChannels, StorePermissions storePermissions) {
|
|
m.checkNotNullParameter(observationDeck, "observationDeck");
|
|
m.checkNotNullParameter(storeChannels, "channelsStore");
|
|
m.checkNotNullParameter(storePermissions, "permissionsStore");
|
|
return ObservationDeck.connectRx$default(observationDeck, new ObservationDeck.UpdateSource[]{storeChannels, storePermissions}, false, null, null, new GuildScheduledEventUtilities$Companion$observeGuildScheduledEventCreatableChannelsForGuild$1(j, storeChannels, storePermissions), 14, null);
|
|
}
|
|
}
|
|
}
|