442 lines
20 KiB
Java
442 lines
20 KiB
Java
package com.discord.stores;
|
|
|
|
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.domain.ModelApplicationStream;
|
|
import com.discord.models.domain.ModelPayload;
|
|
import com.discord.models.guild.Guild;
|
|
import com.discord.models.member.GuildMember;
|
|
import com.discord.models.user.MeUser;
|
|
import com.discord.rtcconnection.RtcConnection;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import com.discord.stores.updates.ObservationDeckProvider;
|
|
import com.discord.utilities.guildmember.GuildMemberUtilsKt;
|
|
import com.discord.utilities.media.AppSound;
|
|
import com.discord.utilities.media.AppSoundManager;
|
|
import com.discord.utilities.time.Clock;
|
|
import com.discord.utilities.user.UserUtils;
|
|
import com.discord.utilities.voice.VoiceChannelJoinability;
|
|
import com.discord.utilities.voice.VoiceChannelJoinabilityUtils;
|
|
import d0.t.h0;
|
|
import d0.z.d.m;
|
|
import java.util.Collection;
|
|
import java.util.Map;
|
|
import kotlin.NoWhenBranchMatchedException;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
import rx.subjects.PublishSubject;
|
|
/* compiled from: StoreVoiceChannelSelected.kt */
|
|
public final class StoreVoiceChannelSelected extends StoreV2 implements DispatchHandler {
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final long VOICE_CHANNEL_ID_NONE = 0;
|
|
private final Clock clock;
|
|
private final Dispatcher dispatcher;
|
|
private long lastSelectedVoiceChannelId;
|
|
private final ObservationDeck observationDeck;
|
|
private Long preselectedVoiceChannelId;
|
|
private long selectedVoiceChannelId;
|
|
private String sessionId;
|
|
private final StoreStream stream;
|
|
private long timeSelectedMs;
|
|
|
|
/* compiled from: StoreVoiceChannelSelected.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreVoiceChannelSelected.kt */
|
|
public enum JoinVoiceChannelResult {
|
|
SUCCESS,
|
|
DEFERRED_UNTIL_SESSION_START,
|
|
ALREADY_CONNECTED,
|
|
FAILED_PERMISSIONS_MISSING,
|
|
FAILED_GUILD_VIDEO_AT_CAPACITY,
|
|
FAILED_CHANNEL_FULL,
|
|
FAILED_CHANNEL_DOES_NOT_EXIST
|
|
}
|
|
|
|
public final /* synthetic */ class WhenMappings {
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$1;
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$2;
|
|
|
|
static {
|
|
VoiceChannelJoinability.values();
|
|
int[] iArr = new int[5];
|
|
$EnumSwitchMapping$0 = iArr;
|
|
VoiceChannelJoinability voiceChannelJoinability = VoiceChannelJoinability.CAN_JOIN;
|
|
iArr[voiceChannelJoinability.ordinal()] = 1;
|
|
VoiceChannelJoinability voiceChannelJoinability2 = VoiceChannelJoinability.PERMISSIONS_MISSING;
|
|
iArr[voiceChannelJoinability2.ordinal()] = 2;
|
|
VoiceChannelJoinability voiceChannelJoinability3 = VoiceChannelJoinability.CHANNEL_FULL;
|
|
iArr[voiceChannelJoinability3.ordinal()] = 3;
|
|
VoiceChannelJoinability voiceChannelJoinability4 = VoiceChannelJoinability.GUILD_VIDEO_AT_CAPACITY;
|
|
iArr[voiceChannelJoinability4.ordinal()] = 4;
|
|
VoiceChannelJoinability voiceChannelJoinability5 = VoiceChannelJoinability.CHANNEL_DOES_NOT_EXIST;
|
|
iArr[voiceChannelJoinability5.ordinal()] = 5;
|
|
VoiceChannelJoinability.values();
|
|
int[] iArr2 = new int[5];
|
|
$EnumSwitchMapping$1 = iArr2;
|
|
iArr2[voiceChannelJoinability2.ordinal()] = 1;
|
|
iArr2[voiceChannelJoinability4.ordinal()] = 2;
|
|
iArr2[voiceChannelJoinability3.ordinal()] = 3;
|
|
iArr2[voiceChannelJoinability5.ordinal()] = 4;
|
|
iArr2[voiceChannelJoinability.ordinal()] = 5;
|
|
GuildVerificationLevel.values();
|
|
int[] iArr3 = new int[5];
|
|
$EnumSwitchMapping$2 = iArr3;
|
|
iArr3[GuildVerificationLevel.HIGHEST.ordinal()] = 1;
|
|
iArr3[GuildVerificationLevel.HIGH.ordinal()] = 2;
|
|
iArr3[GuildVerificationLevel.MEDIUM.ordinal()] = 3;
|
|
iArr3[GuildVerificationLevel.LOW.ordinal()] = 4;
|
|
iArr3[GuildVerificationLevel.NONE.ordinal()] = 5;
|
|
}
|
|
}
|
|
|
|
public StoreVoiceChannelSelected(StoreStream storeStream, Dispatcher dispatcher, Clock clock, ObservationDeck observationDeck) {
|
|
m.checkNotNullParameter(storeStream, "stream");
|
|
m.checkNotNullParameter(dispatcher, "dispatcher");
|
|
m.checkNotNullParameter(clock, "clock");
|
|
m.checkNotNullParameter(observationDeck, "observationDeck");
|
|
this.stream = storeStream;
|
|
this.dispatcher = dispatcher;
|
|
this.clock = clock;
|
|
this.observationDeck = observationDeck;
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ StoreVoiceChannelSelected(StoreStream storeStream, Dispatcher dispatcher, Clock clock, ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(storeStream, dispatcher, clock, (i & 8) != 0 ? ObservationDeckProvider.get() : observationDeck);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$clearInternal(StoreVoiceChannelSelected storeVoiceChannelSelected) {
|
|
storeVoiceChannelSelected.clearInternal();
|
|
}
|
|
|
|
public static final /* synthetic */ long access$getSelectedVoiceChannelId$p(StoreVoiceChannelSelected storeVoiceChannelSelected) {
|
|
return storeVoiceChannelSelected.selectedVoiceChannelId;
|
|
}
|
|
|
|
public static final /* synthetic */ StoreStream access$getStream$p(StoreVoiceChannelSelected storeVoiceChannelSelected) {
|
|
return storeVoiceChannelSelected.stream;
|
|
}
|
|
|
|
public static final /* synthetic */ long access$getTimeSelectedMs$p(StoreVoiceChannelSelected storeVoiceChannelSelected) {
|
|
return storeVoiceChannelSelected.timeSelectedMs;
|
|
}
|
|
|
|
public static final /* synthetic */ JoinVoiceChannelResult access$selectVoiceChannelInternal(StoreVoiceChannelSelected storeVoiceChannelSelected, long j, boolean z2) {
|
|
return storeVoiceChannelSelected.selectVoiceChannelInternal(j, z2);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setSelectedVoiceChannelId$p(StoreVoiceChannelSelected storeVoiceChannelSelected, long j) {
|
|
storeVoiceChannelSelected.selectedVoiceChannelId = j;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setTimeSelectedMs$p(StoreVoiceChannelSelected storeVoiceChannelSelected, long j) {
|
|
storeVoiceChannelSelected.timeSelectedMs = j;
|
|
}
|
|
|
|
@StoreThread
|
|
private final void clearInternal() {
|
|
Channel channel = StoreStream.Companion.getChannels().getChannel(this.selectedVoiceChannelId);
|
|
if (channel != null && AnimatableValueParser.z2(channel)) {
|
|
AppSoundManager.Provider.INSTANCE.get().play(AppSound.Companion.getSOUND_USER_LEFT());
|
|
}
|
|
selectVoiceChannelInternal(0, false);
|
|
}
|
|
|
|
@StoreThread
|
|
private final VoiceChannelJoinability getJoinability(long j) {
|
|
GuildMaxVideoChannelUsers guildMaxVideoChannelUsers;
|
|
StoreChannels channels$app_productionBetaRelease = this.stream.getChannels$app_productionBetaRelease();
|
|
StoreGuilds guilds$app_productionBetaRelease = this.stream.getGuilds$app_productionBetaRelease();
|
|
StorePermissions permissions$app_productionBetaRelease = this.stream.getPermissions$app_productionBetaRelease();
|
|
StoreVoiceStates voiceStates$app_productionBetaRelease = this.stream.getVoiceStates$app_productionBetaRelease();
|
|
StoreStageInstances stageInstances$app_productionBetaRelease = this.stream.getStageInstances$app_productionBetaRelease();
|
|
Channel findChannelByIdInternal$app_productionBetaRelease = channels$app_productionBetaRelease.findChannelByIdInternal$app_productionBetaRelease(j);
|
|
if (findChannelByIdInternal$app_productionBetaRelease == null) {
|
|
return VoiceChannelJoinability.CHANNEL_DOES_NOT_EXIST;
|
|
}
|
|
StageInstance stageInstanceForChannelInternal = stageInstances$app_productionBetaRelease.getStageInstanceForChannelInternal(j);
|
|
Map map = (Map) a.c(findChannelByIdInternal$app_productionBetaRelease, voiceStates$app_productionBetaRelease.get());
|
|
if (map == null) {
|
|
map = h0.emptyMap();
|
|
}
|
|
Long l = permissions$app_productionBetaRelease.getPermissionsByChannel().get(Long.valueOf(j));
|
|
Guild guild = (Guild) a.c(findChannelByIdInternal$app_productionBetaRelease, guilds$app_productionBetaRelease.getGuilds());
|
|
GuildVerificationLevel verificationLevelTriggered = guild != null ? getVerificationLevelTriggered(guild) : GuildVerificationLevel.NONE;
|
|
VoiceChannelJoinabilityUtils voiceChannelJoinabilityUtils = VoiceChannelJoinabilityUtils.INSTANCE;
|
|
Collection<VoiceState> values = map.values();
|
|
if (guild == null || (guildMaxVideoChannelUsers = guild.getMaxVideoChannelUsers()) == null) {
|
|
guildMaxVideoChannelUsers = GuildMaxVideoChannelUsers.Unlimited.INSTANCE;
|
|
}
|
|
return voiceChannelJoinabilityUtils.computeJoinability(findChannelByIdInternal$app_productionBetaRelease, values, l, guildMaxVideoChannelUsers, verificationLevelTriggered, Long.valueOf(this.selectedVoiceChannelId), stageInstanceForChannelInternal);
|
|
}
|
|
|
|
@StoreThread
|
|
private final GuildVerificationLevel getVerificationLevelTriggered(Guild guild) {
|
|
StoreGuilds guilds$app_productionBetaRelease = this.stream.getGuilds$app_productionBetaRelease();
|
|
StoreUser users$app_productionBetaRelease = this.stream.getUsers$app_productionBetaRelease();
|
|
GuildVerificationLevel verificationLevel = guild.getVerificationLevel();
|
|
Map<Long, GuildMember> map = guilds$app_productionBetaRelease.getMembers().get(Long.valueOf(guild.getId()));
|
|
MeUser me2 = users$app_productionBetaRelease.getMe();
|
|
GuildMember guildMember = map != null ? map.get(Long.valueOf(me2.getId())) : null;
|
|
boolean isOwner = guild.isOwner(me2.getId());
|
|
boolean z2 = guildMember != null && (guildMember.getRoles().isEmpty() ^ true);
|
|
UserUtils userUtils = UserUtils.INSTANCE;
|
|
boolean hasPhone = userUtils.getHasPhone(me2);
|
|
Long l = guilds$app_productionBetaRelease.getGuildsJoinedAt().get(Long.valueOf(guild.getId()));
|
|
if (isOwner || z2 || hasPhone) {
|
|
return GuildVerificationLevel.NONE;
|
|
}
|
|
int ordinal = verificationLevel.ordinal();
|
|
if (ordinal == 0) {
|
|
return GuildVerificationLevel.NONE;
|
|
}
|
|
if (ordinal != 1) {
|
|
if (ordinal != 2) {
|
|
if (ordinal != 3) {
|
|
if (ordinal == 4) {
|
|
return GuildVerificationLevel.HIGH;
|
|
}
|
|
} else if (l != null && !GuildMemberUtilsKt.isGuildMemberOldEnough(l.longValue())) {
|
|
return GuildVerificationLevel.HIGH;
|
|
}
|
|
} else if (!userUtils.isAccountOldEnough(me2, this.clock)) {
|
|
return GuildVerificationLevel.MEDIUM;
|
|
}
|
|
} else if (!me2.isVerified()) {
|
|
return GuildVerificationLevel.LOW;
|
|
}
|
|
return GuildVerificationLevel.NONE;
|
|
}
|
|
|
|
@StoreThread
|
|
private final JoinVoiceChannelResult selectVoiceChannelInternal(long j, boolean z2) {
|
|
boolean z3;
|
|
Channel channel;
|
|
if (this.sessionId == null) {
|
|
this.preselectedVoiceChannelId = Long.valueOf(j);
|
|
return JoinVoiceChannelResult.DEFERRED_UNTIL_SESSION_START;
|
|
}
|
|
this.preselectedVoiceChannelId = null;
|
|
if (j == this.selectedVoiceChannelId) {
|
|
return JoinVoiceChannelResult.ALREADY_CONNECTED;
|
|
}
|
|
VoiceChannelJoinability joinability = getJoinability(j);
|
|
int ordinal = joinability.ordinal();
|
|
if (ordinal != 0) {
|
|
if (ordinal != 1) {
|
|
if (ordinal != 2) {
|
|
if (ordinal != 3) {
|
|
if (ordinal != 4) {
|
|
throw new NoWhenBranchMatchedException();
|
|
}
|
|
}
|
|
}
|
|
z3 = false;
|
|
}
|
|
z3 = z2;
|
|
} else {
|
|
z3 = true;
|
|
}
|
|
long j2 = this.selectedVoiceChannelId;
|
|
if (z3) {
|
|
if (!z2 && (channel = StoreStream.Companion.getChannels().getChannel(j)) != null && AnimatableValueParser.z2(channel)) {
|
|
AppSoundManager.Provider.INSTANCE.get().play(AppSound.Companion.getSOUND_USER_JOINED());
|
|
}
|
|
this.selectedVoiceChannelId = j;
|
|
if (j > 0) {
|
|
this.lastSelectedVoiceChannelId = j;
|
|
}
|
|
} else {
|
|
this.selectedVoiceChannelId = 0;
|
|
}
|
|
if (j2 != this.selectedVoiceChannelId) {
|
|
markChanged();
|
|
}
|
|
if (z3) {
|
|
return JoinVoiceChannelResult.SUCCESS;
|
|
}
|
|
int ordinal2 = joinability.ordinal();
|
|
if (ordinal2 == 0) {
|
|
return JoinVoiceChannelResult.SUCCESS;
|
|
}
|
|
if (ordinal2 == 1) {
|
|
return JoinVoiceChannelResult.FAILED_PERMISSIONS_MISSING;
|
|
}
|
|
if (ordinal2 == 2) {
|
|
return JoinVoiceChannelResult.FAILED_GUILD_VIDEO_AT_CAPACITY;
|
|
}
|
|
if (ordinal2 == 3) {
|
|
return JoinVoiceChannelResult.FAILED_CHANNEL_FULL;
|
|
}
|
|
if (ordinal2 == 4) {
|
|
return JoinVoiceChannelResult.FAILED_CHANNEL_DOES_NOT_EXIST;
|
|
}
|
|
throw new NoWhenBranchMatchedException();
|
|
}
|
|
|
|
@StoreThread
|
|
private final void validateSelectedVoiceChannel() {
|
|
long j = this.selectedVoiceChannelId;
|
|
if (j != 0) {
|
|
if (this.stream.getChannels$app_productionBetaRelease().findChannelByIdInternal$app_productionBetaRelease(this.selectedVoiceChannelId) == null) {
|
|
clearInternal();
|
|
}
|
|
if (this.selectedVoiceChannelId != j) {
|
|
markChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void clear() {
|
|
this.dispatcher.schedule(new StoreVoiceChannelSelected$clear$1(this));
|
|
}
|
|
|
|
public final long getLastSelectedVoiceChannelId() {
|
|
return this.lastSelectedVoiceChannelId;
|
|
}
|
|
|
|
public final long getSelectedVoiceChannelId() {
|
|
return this.selectedVoiceChannelId;
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleAuthToken(String str) {
|
|
if (str == null) {
|
|
clearInternal();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleChannelOrThreadCreateOrUpdate() {
|
|
validateSelectedVoiceChannel();
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleChannelOrThreadDelete() {
|
|
validateSelectedVoiceChannel();
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleConnectionOpen(ModelPayload modelPayload) {
|
|
m.checkNotNullParameter(modelPayload, "payload");
|
|
this.sessionId = modelPayload.getSessionId();
|
|
Long l = this.preselectedVoiceChannelId;
|
|
if (l != null) {
|
|
selectVoiceChannelInternal(l.longValue(), false);
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleGuildMemberAdd(com.discord.api.guildmember.GuildMember guildMember) {
|
|
m.checkNotNullParameter(guildMember, "member");
|
|
if (guildMember.j().i() == this.stream.getUsers$app_productionBetaRelease().getMeInternal$app_productionBetaRelease().getId()) {
|
|
validateSelectedVoiceChannel();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleGuildRemove() {
|
|
validateSelectedVoiceChannel();
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleGuildRoleCreateOrUpdate() {
|
|
validateSelectedVoiceChannel();
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleGuildRoleRemove() {
|
|
validateSelectedVoiceChannel();
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleRtcConnectionStateChanged(RtcConnection.State state) {
|
|
m.checkNotNullParameter(state, "state");
|
|
if (state instanceof RtcConnection.State.f) {
|
|
Channel findChannelByIdInternal$app_productionBetaRelease = this.stream.getChannels$app_productionBetaRelease().findChannelByIdInternal$app_productionBetaRelease(this.selectedVoiceChannelId);
|
|
Guild guild = this.stream.getGuilds$app_productionBetaRelease().getGuildsInternal$app_productionBetaRelease().get(findChannelByIdInternal$app_productionBetaRelease != null ? Long.valueOf(findChannelByIdInternal$app_productionBetaRelease.e()) : null);
|
|
if (guild != null) {
|
|
Long afkChannelId = guild.getAfkChannelId();
|
|
long j = this.selectedVoiceChannelId;
|
|
if (afkChannelId != null && afkChannelId.longValue() == j && this.stream.getMediaEngine$app_productionBetaRelease().getSelectedVideoInputDeviceBlocking() != null) {
|
|
this.stream.getMediaEngine$app_productionBetaRelease().selectVideoInputDevice(null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleStreamTargeted(String str) {
|
|
m.checkNotNullParameter(str, "streamKey");
|
|
selectVoiceChannelInternal(ModelApplicationStream.Companion.decodeStreamKey(str).getChannelId(), false);
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleVoiceStateUpdates(VoiceState voiceState) {
|
|
Channel findChannelByIdInternal$app_productionBetaRelease;
|
|
m.checkNotNullParameter(voiceState, "voiceState");
|
|
if (this.stream.getUsers$app_productionBetaRelease().getMeInternal$app_productionBetaRelease().getId() == voiceState.m() && (findChannelByIdInternal$app_productionBetaRelease = this.stream.getChannels$app_productionBetaRelease().findChannelByIdInternal$app_productionBetaRelease(this.selectedVoiceChannelId)) != null && findChannelByIdInternal$app_productionBetaRelease.e() == voiceState.c()) {
|
|
Long a = voiceState.a();
|
|
long j = this.selectedVoiceChannelId;
|
|
if ((a != null && a.longValue() == j) || !m.areEqual(voiceState.k(), this.sessionId)) {
|
|
if (!m.areEqual(voiceState.k(), this.sessionId)) {
|
|
clearInternal();
|
|
}
|
|
} else if (a != null) {
|
|
selectVoiceChannelInternal(a.longValue(), true);
|
|
AppSoundManager.Provider.INSTANCE.get().play(AppSound.Companion.getSOUND_USER_MOVED());
|
|
} else {
|
|
clearInternal();
|
|
}
|
|
}
|
|
}
|
|
|
|
public final Observable<Channel> observeSelectedChannel() {
|
|
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this, this.stream.getChannels$app_productionBetaRelease()}, false, null, null, new StoreVoiceChannelSelected$observeSelectedChannel$1(this), 14, null);
|
|
}
|
|
|
|
public final Observable<Long> observeSelectedVoiceChannelId() {
|
|
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreVoiceChannelSelected$observeSelectedVoiceChannelId$1(this), 14, null);
|
|
}
|
|
|
|
public final Observable<Long> observeTimeSelectedMs() {
|
|
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreVoiceChannelSelected$observeTimeSelectedMs$1(this), 14, null);
|
|
}
|
|
|
|
public final Observable<JoinVoiceChannelResult> selectVoiceChannel(long j) {
|
|
Channel channel = this.stream.getChannels$app_productionBetaRelease().getChannel(j);
|
|
if (channel != null && AnimatableValueParser.u1(channel)) {
|
|
StoreStream.Companion.getMediaEngine().setAudioInputEnabled(false);
|
|
}
|
|
PublishSubject l0 = PublishSubject.l0();
|
|
this.dispatcher.schedule(new StoreVoiceChannelSelected$selectVoiceChannel$1(this, j, l0));
|
|
m.checkNotNullExpressionValue(l0, "resultSubject");
|
|
return l0;
|
|
}
|
|
|
|
@Override // com.discord.stores.StoreV2
|
|
@StoreThread
|
|
public void snapshotData() {
|
|
super.snapshotData();
|
|
long j = 0;
|
|
if (this.selectedVoiceChannelId > 0) {
|
|
j = this.clock.currentTimeMillis();
|
|
}
|
|
this.timeSelectedMs = j;
|
|
}
|
|
}
|