discord-jadx/app/src/main/java/com/discord/stores/StoreVoiceChannelSelected.java

450 lines
20 KiB
Java

package com.discord.stores;
import b.d.b.a.a;
import com.discord.api.channel.Channel;
import com.discord.api.channel.ChannelUtils;
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 && ChannelUtils.F(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_productionCanaryRelease = this.stream.getChannels$app_productionCanaryRelease();
StoreGuilds guilds$app_productionCanaryRelease = this.stream.getGuilds$app_productionCanaryRelease();
StorePermissions permissions$app_productionCanaryRelease = this.stream.getPermissions$app_productionCanaryRelease();
StoreVoiceStates voiceStates$app_productionCanaryRelease = this.stream.getVoiceStates$app_productionCanaryRelease();
StoreStageInstances stageInstances$app_productionCanaryRelease = this.stream.getStageInstances$app_productionCanaryRelease();
Channel findChannelByIdInternal$app_productionCanaryRelease = channels$app_productionCanaryRelease.findChannelByIdInternal$app_productionCanaryRelease(j);
if (findChannelByIdInternal$app_productionCanaryRelease == null) {
return VoiceChannelJoinability.CHANNEL_DOES_NOT_EXIST;
}
StageInstance stageInstanceForChannelInternal = stageInstances$app_productionCanaryRelease.getStageInstanceForChannelInternal(j);
Map map = (Map) a.u0(findChannelByIdInternal$app_productionCanaryRelease, voiceStates$app_productionCanaryRelease.get());
if (map == null) {
map = h0.emptyMap();
}
Long l = permissions$app_productionCanaryRelease.getPermissionsByChannel().get(Long.valueOf(j));
Guild guild = (Guild) a.u0(findChannelByIdInternal$app_productionCanaryRelease, guilds$app_productionCanaryRelease.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_productionCanaryRelease, values, l, guildMaxVideoChannelUsers, verificationLevelTriggered, Long.valueOf(this.selectedVoiceChannelId), stageInstanceForChannelInternal);
}
@StoreThread
private final GuildVerificationLevel getVerificationLevelTriggered(Guild guild) {
StoreGuilds guilds$app_productionCanaryRelease = this.stream.getGuilds$app_productionCanaryRelease();
StoreUser users$app_productionCanaryRelease = this.stream.getUsers$app_productionCanaryRelease();
GuildVerificationLevel verificationLevel = guild.getVerificationLevel();
Map map = (Map) a.d(guild, guilds$app_productionCanaryRelease.getMembers());
MeUser me2 = users$app_productionCanaryRelease.getMe();
GuildMember guildMember = map != null ? (GuildMember) 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 = (Long) a.d(guild, guilds$app_productionCanaryRelease.getGuildsJoinedAt());
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 && ChannelUtils.F(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_productionCanaryRelease().findChannelByIdInternal$app_productionCanaryRelease(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 Channel getSelectedVoiceChannel() {
return this.stream.getChannels$app_productionCanaryRelease().findChannelByIdInternal$app_productionCanaryRelease(this.selectedVoiceChannelId);
}
public final long getSelectedVoiceChannelId() {
return this.selectedVoiceChannelId;
}
public final long getTimeSelectedMs() {
return this.timeSelectedMs;
}
@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.m().getId() == this.stream.getUsers$app_productionCanaryRelease().getMeInternal$app_productionCanaryRelease().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_productionCanaryRelease = this.stream.getChannels$app_productionCanaryRelease().findChannelByIdInternal$app_productionCanaryRelease(this.selectedVoiceChannelId);
Guild guild = this.stream.getGuilds$app_productionCanaryRelease().getGuildsInternal$app_productionCanaryRelease().get(findChannelByIdInternal$app_productionCanaryRelease != null ? Long.valueOf(findChannelByIdInternal$app_productionCanaryRelease.f()) : null);
if (guild != null) {
Long afkChannelId = guild.getAfkChannelId();
long j = this.selectedVoiceChannelId;
if (afkChannelId != null && afkChannelId.longValue() == j && this.stream.getMediaEngine$app_productionCanaryRelease().getSelectedVideoInputDeviceBlocking() != null) {
this.stream.getMediaEngine$app_productionCanaryRelease().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_productionCanaryRelease;
m.checkNotNullParameter(voiceState, "voiceState");
if (this.stream.getUsers$app_productionCanaryRelease().getMeInternal$app_productionCanaryRelease().getId() == voiceState.m() && (findChannelByIdInternal$app_productionCanaryRelease = this.stream.getChannels$app_productionCanaryRelease().findChannelByIdInternal$app_productionCanaryRelease(this.selectedVoiceChannelId)) != null && findChannelByIdInternal$app_productionCanaryRelease.f() == 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_productionCanaryRelease()}, 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_productionCanaryRelease().getChannel(j);
if (channel != null && ChannelUtils.z(channel)) {
StoreStream.Companion.getMediaEngine().setAudioInputEnabled(false);
}
PublishSubject k0 = PublishSubject.k0();
this.dispatcher.schedule(new StoreVoiceChannelSelected$selectVoiceChannel$1(this, j, k0));
m.checkNotNullExpressionValue(k0, "resultSubject");
return k0;
}
@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;
}
}