186 lines
8.7 KiB
TypeScript
186 lines
8.7 KiB
TypeScript
// Metro module 14989 (f14990).
|
|
import EmbeddedActivitiesStore from "../activities/EmbeddedActivitiesStore";
|
|
import StageInstanceStore from "../stage_channels/StageInstanceStore";
|
|
import { isVoiceChannel } from "../../records/ChannelRecord";
|
|
import ApplicationStreamingStore from "../../stores/ApplicationStreamingStore";
|
|
import AuthenticationStore from "../../stores/AuthenticationStore";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import RelationshipStore from "../../stores/RelationshipStore";
|
|
import SelectedChannelStore from "../../stores/SelectedChannelStore";
|
|
import UserGuildSettingsStore from "../../stores/UserGuildSettingsStore";
|
|
import VoiceStateStore from "../../stores/VoiceStateStore";
|
|
import { BasicPermissions } from "../../Constants";
|
|
import { ChannelTypes } from "../../_bundle/Module692";
|
|
import { useStateFromStores, useStateFromStoresArray, useStateFromStoresObject } from "../../_bundle/Module589";
|
|
import { useIsDontBadgeMutedVcsEnabled } from "./DontBadgeMutedVcsExperiment";
|
|
import { useGuildActiveEvent } from "../guild_scheduled_events/useGuildScheduledEvents";
|
|
import { hasBlockedOrIgnoredUserIds, filterBlockedUsersFromVoiceStates, filterOutStreamsByBlockedOwner } from "../blocking/BlockedUserUtils";
|
|
import { getEmbeddedActivityLocationChannelId } from "../activities/utils/embeddedActivityLocationUtils";
|
|
import { useIsActivitiesInTextEnabled } from "../activities/ActivitiesInTextUtils";
|
|
import SnowflakeUtils from "../../utils/SnowflakeUtils";
|
|
import { JOIN_VOCAL_CHANNEL_PERMISSIONS } from "../stage_channels/StageChannelPermissions";
|
|
const canConnectToChannel = function canConnectToChannel(basicChannel, a1, r6 = PermissionStore) {
|
|
return basicChannel != null && basicChannel.type !== ChannelTypes.GUILD_STAGE_VOICE && a1 !== basicChannel.id && r6.canBasicChannel(BasicPermissions.VIEW_CHANNEL, basicChannel);
|
|
};
|
|
export default function useGuildMediaState(a0) {
|
|
let isDontBadgeMutedVcsEnabled, guildActiveEvent, stateFromStoresArray, isActivitiesInTextEnabled, guildHasVoice, guildHasVideo, selectedVoiceChannelHasVideo, id;
|
|
const stateFromStores = useStateFromStores([UserGuildSettingsStore], () => UserGuildSettingsStore.isMuted(a0));
|
|
isDontBadgeMutedVcsEnabled = useIsDontBadgeMutedVcsEnabled("useGuildMediaState");
|
|
guildActiveEvent = useGuildActiveEvent(a0);
|
|
stateFromStoresArray = useStateFromStoresArray([EmbeddedActivitiesStore, RelationshipStore], () => EmbeddedActivitiesStore.getEmbeddedActivitiesForGuild(a0).filter((item) => !hasBlockedOrIgnoredUserIds([...item.userIds], RelationshipStore.getBlockedOrIgnoredIDs())));
|
|
isActivitiesInTextEnabled = useIsActivitiesInTextEnabled(getEmbeddedActivityLocationChannelId(stateFromStoresArray[0]?.location));
|
|
const stateFromStoresObject = useStateFromStoresObject([SelectedChannelStore, VoiceStateStore, GuildStore, PermissionStore, ChannelStore, UserGuildSettingsStore], () => {
|
|
const voiceChannelId = SelectedChannelStore.getVoiceChannelId();
|
|
const afkChannelId = GuildStore.getGuild(a0)?.afkChannelId;
|
|
const usersWithVideo = VoiceStateStore.getUsersWithVideo(a0);
|
|
const r36 = filterBlockedUsersFromVoiceStates(VoiceStateStore.getVoiceStates(a0));
|
|
let c27881_2 = r36;
|
|
let guildHasVoice2 = false;
|
|
if (!stateFromStores) {
|
|
guildHasVoice2 = false;
|
|
for (const key in r36) {
|
|
guildHasVoice2 = false;
|
|
const channelId = r36[key].channelId;
|
|
if (channelId != null) {
|
|
const basicChannel = ChannelStore.getBasicChannel(channelId);
|
|
const r19 = afkChannelId == null ? void 0 : afkChannelId;
|
|
if (PermissionStore !== void 0 && basicChannel != null && basicChannel.type !== ChannelTypes.GUILD_STAGE_VOICE && r19 !== basicChannel.id && PermissionStore.canBasicChannel(BasicPermissions.VIEW_CHANNEL, basicChannel)) {
|
|
guildHasVoice2 = true;
|
|
if (!isDontBadgeMutedVcsEnabled) {
|
|
break;
|
|
}
|
|
const isGuildOrCategoryOrChannelMuted = UserGuildSettingsStore.isGuildOrCategoryOrChannelMuted(a0, channelId);
|
|
guildHasVoice2 = true;
|
|
if (!isGuildOrCategoryOrChannelMuted) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
guildHasVoice2 = false;
|
|
}
|
|
return {
|
|
guildHasVoice: guildHasVoice2,
|
|
guildHasVideo: (() => {
|
|
if (stateFromStores) {
|
|
return false;
|
|
}
|
|
for (const item of usersWithVideo) {
|
|
const channelId = c27881_2[item]?.channelId;
|
|
if (channelId == null) {
|
|
continue;
|
|
}
|
|
const basicChannel = ChannelStore.getBasicChannel(channelId);
|
|
let r38 = afkChannelId;
|
|
if (afkChannelId == null) {
|
|
r38 = void 0;
|
|
}
|
|
if (!canConnectToChannel(basicChannel, r38, PermissionStore)) {
|
|
continue;
|
|
}
|
|
if (isDontBadgeMutedVcsEnabled && UserGuildSettingsStore.isGuildOrCategoryOrChannelMuted(a0, channelId)) {
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
})(),
|
|
selectedVoiceChannelHasVideo: voiceChannelId != null && VoiceStateStore.hasVideo(voiceChannelId)
|
|
};
|
|
}, [a0, stateFromStores, isDontBadgeMutedVcsEnabled]);
|
|
guildHasVoice = stateFromStoresObject.guildHasVoice;
|
|
guildHasVideo = stateFromStoresObject.guildHasVideo;
|
|
selectedVoiceChannelHasVideo = stateFromStoresObject.selectedVoiceChannelHasVideo;
|
|
id = AuthenticationStore.getId();
|
|
return useStateFromStoresObject([SelectedChannelStore, ChannelStore, EmbeddedActivitiesStore, StageInstanceStore, ApplicationStreamingStore, PermissionStore, UserGuildSettingsStore], () => {
|
|
let activeEvent, audio, liveStage, screenshare, video;
|
|
const voiceChannelId = SelectedChannelStore.getVoiceChannelId();
|
|
const guild_id = ChannelStore.getChannel(voiceChannelId)?.guild_id;
|
|
let isCurrentUserConnected = guild_id === a0;
|
|
if (!isCurrentUserConnected && stateFromStores) {
|
|
return {
|
|
audio: false,
|
|
video: false,
|
|
screenshare: false,
|
|
liveStage: false,
|
|
activeEvent: false,
|
|
activity: false,
|
|
isCurrentUserConnected: false
|
|
};
|
|
}
|
|
const r31 = SnowflakeUtils.keys(StageInstanceStore.getStageInstancesByGuild(a0)).some((item) => {
|
|
const channel = ChannelStore.getChannel(item);
|
|
return channel != null && PermissionStore.can(JOIN_VOCAL_CHANNEL_PERMISSIONS, channel);
|
|
});
|
|
let r32 = isCurrentUserConnected;
|
|
if (isCurrentUserConnected) {
|
|
const channel = ChannelStore.getChannel(voiceChannelId);
|
|
let r36 = channel == null ? void 0 : channel.isGuildStageVoice();
|
|
if (r36 == null) {
|
|
r36 = false;
|
|
}
|
|
r32 = r36;
|
|
}
|
|
const r2 = !!isCurrentUserConnected && ApplicationStreamingStore.getActiveStreamForUser(id, a0) != null;
|
|
const r53 = filterOutStreamsByBlockedOwner(ApplicationStreamingStore.getAllApplicationStreams()).some((item) => {
|
|
const guildId = item.guildId;
|
|
let r7 = guildId !== a0;
|
|
if (!r7) {
|
|
let r8 = isDontBadgeMutedVcsEnabled;
|
|
if (isDontBadgeMutedVcsEnabled) {
|
|
r8 = UserGuildSettingsStore.isGuildOrCategoryOrChannelMuted(a0, item.channelId);
|
|
}
|
|
r7 = r8;
|
|
}
|
|
return !r7;
|
|
});
|
|
let activity = (() => {
|
|
if (isActivitiesInTextEnabled) {
|
|
return stateFromStoresArray.length > 0;
|
|
}
|
|
for (const item of stateFromStoresArray) {
|
|
const channel = ChannelStore.getChannel(getEmbeddedActivityLocationChannelId(item.location));
|
|
if (channel == null) {
|
|
continue;
|
|
}
|
|
if (!isVoiceChannel(channel.type)) {
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
})();
|
|
const r6 = EmbeddedActivitiesStore.getEmbeddedActivitiesForGuild(a0).length > 0;
|
|
if (isCurrentUserConnected) {
|
|
const channel_id = guildActiveEvent?.channel_id;
|
|
const r68 = isCurrentUserConnected ? selectedVoiceChannelHasVideo : isCurrentUserConnected;
|
|
activeEvent = channel_id === voiceChannelId;
|
|
audio = true;
|
|
video = r68;
|
|
activity = r6;
|
|
screenshare = r2;
|
|
liveStage = r32;
|
|
} else {
|
|
audio = guildHasVoice;
|
|
activeEvent = guildActiveEvent != null;
|
|
video = guildHasVideo;
|
|
screenshare = r53;
|
|
liveStage = r31;
|
|
}
|
|
if (!isCurrentUserConnected) {
|
|
isCurrentUserConnected = r32;
|
|
}
|
|
return {
|
|
audio,
|
|
video,
|
|
screenshare,
|
|
liveStage,
|
|
activeEvent,
|
|
activity,
|
|
isCurrentUserConnected
|
|
};
|
|
}, [a0, stateFromStores, selectedVoiceChannelHasVideo, id, isActivitiesInTextEnabled, stateFromStoresArray, guildActiveEvent, guildHasVoice, guildHasVideo, isDontBadgeMutedVcsEnabled]);
|
|
};
|