/* * Vencord, a Discord client mod * Copyright (c) 2024 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import { classNameFactory } from "@api/Styles"; import { findComponentByCodeLazy, findStoreLazy } from "@webpack"; import { ChannelStore, GuildStore, PermissionsBits, PermissionStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; import { User } from "discord-types/general"; import { Icons } from ".."; import { settings } from "../settings"; import { SvgIconProps, VoiceActivityIconProps } from "../types"; const cl = classNameFactory("vc-uvs-"); const VoiceStateStore = findStoreLazy("VoiceStateStore"); const UsersList = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); const SvgIcon = ({ className, height = 24, path, viewBox = "0 0 24 24", width = 24, ...props }: SvgIconProps) => ( ); export default function VoiceActivityIcon({ user, needContainer, inProfile }: VoiceActivityIconProps) { const currentUserVoiceState = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(UserStore.getCurrentUser().id)); const targetUserVoiceState = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(user.id)); if (!targetUserVoiceState) return null; const channel = ChannelStore.getChannel(targetUserVoiceState.channelId); if (!channel) return null; const canConnectToChannel = PermissionStore.can(PermissionsBits.CONNECT, channel); const guild = GuildStore.getGuild(channel.guild_id); const channelPath = `/channels/${guild ? guild.id : "@me"}/${channel.id}`; let className = inProfile ? cl("profile-icon") : cl("icon"); if (targetUserVoiceState.selfStream) className = cl("icon-live"); else if (channel.id === currentUserVoiceState?.channelId) className += ` ${cl("icon-current-call")}`; if (needContainer) className += ` ${cl("icon-container")}`; let TooltipIcon = Icons.Speaker; let TooltipSubIcon = Icons.Speaker; if (!canConnectToChannel && guild) TooltipIcon = Icons.Locked; else if (targetUserVoiceState.selfVideo) TooltipIcon = Icons.Video; else if (targetUserVoiceState.selfDeaf || targetUserVoiceState.deaf) TooltipIcon = Icons.Deafened; else if (targetUserVoiceState.selfMute || targetUserVoiceState.mute) TooltipIcon = Icons.Muted; let headerText = ""; let subtext = ""; if (guild) { headerText = guild.name; subtext = channel.name; if (channel.type === 13) TooltipSubIcon = Icons.Stage; } else { headerText = channel.type === 1 ? "Private Call" : "Group Call"; subtext = channel.type === 1 ? UserStore.getUser(channel.recipients.find(r => r !== UserStore.getCurrentUser().id)!).username : channel.name; TooltipSubIcon = channel.type === 1 ? Icons.Private : Icons.Group; } let voiceChannelUsers: User[] | undefined; if (settings.store.showUsersInVoiceActivity) { voiceChannelUsers = (Object.values(VoiceStateStore.getVoiceStatesForChannel(channel?.id)) as { userId: string; }[]).map(vs => UserStore.getUser(vs.userId)); } return (
{ Vencord.Webpack.Common.NavigationRouter.transitionTo(channelPath); } } >
{headerText}
{subtext}
{ voiceChannelUsers &&
}
} > {tooltipProps => targetUserVoiceState.selfStream ?
Live
: inProfile ? : } ); }