package com.discord.utilities.voice; import c.d.b.a.a; import com.airbnb.lottie.parser.AnimatableValueParser; import com.discord.api.channel.Channel; import com.discord.api.guild.GuildMaxVideoChannelUsers; import com.discord.api.guild.GuildVerificationLevel; import com.discord.api.stageinstance.StageInstance; import com.discord.api.voice.state.VoiceState; import com.discord.models.guild.Guild; import com.discord.stores.StoreChannels; import com.discord.stores.StoreGuilds; import com.discord.stores.StorePermissions; import com.discord.stores.StoreStageInstances; import com.discord.stores.StoreStream; import com.discord.stores.StoreVoiceChannelSelected; import com.discord.stores.StoreVoiceStates; import com.discord.utilities.guilds.GuildVerificationLevelUtils; import com.discord.utilities.permissions.PermissionUtils; import d0.t.h0; import d0.z.d.m; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.Map; import rx.Observable; /* compiled from: VoiceChannelJoinabilityUtils.kt */ public final class VoiceChannelJoinabilityUtils { public static final VoiceChannelJoinabilityUtils INSTANCE = new VoiceChannelJoinabilityUtils(); private VoiceChannelJoinabilityUtils() { } public static /* synthetic */ Observable observeJoinability$default(VoiceChannelJoinabilityUtils voiceChannelJoinabilityUtils, long j, StoreChannels storeChannels, StoreGuilds storeGuilds, StorePermissions storePermissions, StoreVoiceStates storeVoiceStates, StoreVoiceChannelSelected storeVoiceChannelSelected, StoreStageInstances storeStageInstances, int i, Object obj) { return voiceChannelJoinabilityUtils.observeJoinability(j, (i & 2) != 0 ? StoreStream.Companion.getChannels() : storeChannels, (i & 4) != 0 ? StoreStream.Companion.getGuilds() : storeGuilds, (i & 8) != 0 ? StoreStream.Companion.getPermissions() : storePermissions, (i & 16) != 0 ? StoreStream.Companion.getVoiceStates() : storeVoiceStates, (i & 32) != 0 ? StoreStream.Companion.getVoiceChannelSelected() : storeVoiceChannelSelected, (i & 64) != 0 ? StoreStream.Companion.getStageInstances() : storeStageInstances); } public final VoiceChannelJoinability computeJoinability(Channel channel, Collection collection, Long l, GuildMaxVideoChannelUsers guildMaxVideoChannelUsers, GuildVerificationLevel guildVerificationLevel, Long l2, StageInstance stageInstance) { boolean z2; m.checkNotNullParameter(channel, "channel"); m.checkNotNullParameter(collection, "channelVoiceStates"); m.checkNotNullParameter(guildMaxVideoChannelUsers, "guildMaxVideoChannelUsers"); m.checkNotNullParameter(guildVerificationLevel, "verificationLevelTriggered"); if (AnimatableValueParser.s1(channel)) { return VoiceChannelJoinability.CAN_JOIN; } long h = channel.h(); if (l2 != null && h == l2.longValue()) { return VoiceChannelJoinability.CAN_JOIN; } if (!PermissionUtils.can(1048576, l)) { return VoiceChannelJoinability.PERMISSIONS_MISSING; } boolean z3 = true; if ((guildVerificationLevel != GuildVerificationLevel.NONE) && (stageInstance == null || !AnimatableValueParser.t1(stageInstance))) { return VoiceChannelJoinability.PERMISSIONS_MISSING; } ArrayList arrayList = new ArrayList(); for (Object obj : collection) { Long a = ((VoiceState) obj).a(); if (a != null && a.longValue() == channel.h()) { arrayList.add(obj); } } int size = arrayList.size(); if (!arrayList.isEmpty()) { Iterator it = arrayList.iterator(); while (true) { if (it.hasNext()) { if (((VoiceState) it.next()).j()) { z2 = true; break; } } else { break; } } } z2 = false; boolean can = PermissionUtils.can(16777216, l); if (size >= (channel.B() != 0 ? channel.B() : Integer.MAX_VALUE) && !can) { return VoiceChannelJoinability.CHANNEL_FULL; } boolean can2 = PermissionUtils.can(8, l); if (!z2 || !(guildMaxVideoChannelUsers instanceof GuildMaxVideoChannelUsers.Limited) || size < ((GuildMaxVideoChannelUsers.Limited) guildMaxVideoChannelUsers).a()) { z3 = false; } return (!z3 || can2) ? VoiceChannelJoinability.CAN_JOIN : (((GuildMaxVideoChannelUsers.Limited) guildMaxVideoChannelUsers).a() != size || !can) ? VoiceChannelJoinability.GUILD_VIDEO_AT_CAPACITY : VoiceChannelJoinability.CAN_JOIN; } public final VoiceChannelJoinability getJoinability(long j) { GuildMaxVideoChannelUsers guildMaxVideoChannelUsers; StoreStream.Companion companion = StoreStream.Companion; Channel channel = companion.getChannels().getChannel(j); if (channel == null) { return VoiceChannelJoinability.CHANNEL_DOES_NOT_EXIST; } Map map = (Map) a.c(channel, companion.getVoiceStates().get()); if (map == null) { map = h0.emptyMap(); } Collection values = map.values(); Collection arrayList = new ArrayList<>(); for (Object obj : values) { Long a = ((VoiceState) obj).a(); if (a != null && a.longValue() == j) { arrayList.add(obj); } } StoreStream.Companion companion2 = StoreStream.Companion; Long l = companion2.getPermissions().getPermissionsByChannel().get(Long.valueOf(j)); Guild guild = companion2.getGuilds().getGuild(channel.f()); GuildVerificationLevel verificationLevelTriggered$default = GuildVerificationLevelUtils.getVerificationLevelTriggered$default(GuildVerificationLevelUtils.INSTANCE, channel.f(), null, null, null, 14, null); long selectedVoiceChannelId = companion2.getVoiceChannelSelected().getSelectedVoiceChannelId(); StageInstance stageInstanceForChannel = companion2.getStageInstances().getStageInstanceForChannel(j); if (guild == null || (guildMaxVideoChannelUsers = guild.getMaxVideoChannelUsers()) == null) { guildMaxVideoChannelUsers = GuildMaxVideoChannelUsers.Unlimited.INSTANCE; } return computeJoinability(channel, arrayList, l, guildMaxVideoChannelUsers, verificationLevelTriggered$default, Long.valueOf(selectedVoiceChannelId), stageInstanceForChannel); } public final Observable observeJoinability(long j, StoreChannels storeChannels, StoreGuilds storeGuilds, StorePermissions storePermissions, StoreVoiceStates storeVoiceStates, StoreVoiceChannelSelected storeVoiceChannelSelected, StoreStageInstances storeStageInstances) { m.checkNotNullParameter(storeChannels, "channelsStore"); m.checkNotNullParameter(storeGuilds, "guildsStore"); m.checkNotNullParameter(storePermissions, "permissionsStore"); m.checkNotNullParameter(storeVoiceStates, "voiceStatesStore"); m.checkNotNullParameter(storeVoiceChannelSelected, "voiceChannelSelectedStore"); m.checkNotNullParameter(storeStageInstances, "stageInstancesStore"); Observable Y = storeChannels.observeChannel(j).Y(new VoiceChannelJoinabilityUtils$observeJoinability$1(storeVoiceStates, j, storePermissions, storeGuilds, storeVoiceChannelSelected, storeStageInstances)); m.checkNotNullExpressionValue(Y, "channelsStore\n .o… }\n }\n }"); return Y; } }