MemberCount: also show members in voice (#2937)
Co-authored-by: Vendicated <vendicated@riseup.net>
This commit is contained in:
parent
1d00ba4161
commit
b6e96a4d3b
10 changed files with 140 additions and 27 deletions
|
|
@ -22,13 +22,12 @@ import { Logger } from "@utils/Logger";
|
|||
import { Margins } from "@utils/margins";
|
||||
import { wordsToTitle } from "@utils/text";
|
||||
import definePlugin, { ReporterTestable } from "@utils/types";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { Button, ChannelStore, Forms, GuildMemberStore, SelectedChannelStore, SelectedGuildStore, useMemo, UserStore } from "@webpack/common";
|
||||
import { Button, ChannelStore, Forms, GuildMemberStore, SelectedChannelStore, SelectedGuildStore, useMemo, UserStore, VoiceStateStore } from "@webpack/common";
|
||||
import { ReactElement } from "react";
|
||||
|
||||
import { getCurrentVoice, settings } from "./settings";
|
||||
|
||||
interface VoiceState {
|
||||
interface VoiceStateChangeEvent {
|
||||
userId: string;
|
||||
channelId?: string;
|
||||
oldChannelId?: string;
|
||||
|
|
@ -38,8 +37,6 @@ interface VoiceState {
|
|||
selfMute: boolean;
|
||||
}
|
||||
|
||||
const VoiceStateStore = findByPropsLazy("getVoiceStatesForChannel", "getCurrentClientVoiceChannelId");
|
||||
|
||||
// Mute/Deaf for other people than you is commented out, because otherwise someone can spam it and it will be annoying
|
||||
// Filtering out events is not as simple as just dropping duplicates, as otherwise mute, unmute, mute would
|
||||
// not say the second mute, which would lead you to believe they're unmuted
|
||||
|
|
@ -88,7 +85,7 @@ let StatusMap = {} as Record<string, {
|
|||
// for some ungodly reason
|
||||
let myLastChannelId: string | undefined;
|
||||
|
||||
function getTypeAndChannelId({ channelId, oldChannelId }: VoiceState, isMe: boolean) {
|
||||
function getTypeAndChannelId({ channelId, oldChannelId }: VoiceStateChangeEvent, isMe: boolean) {
|
||||
if (isMe && channelId !== myLastChannelId) {
|
||||
oldChannelId = myLastChannelId;
|
||||
myLastChannelId = channelId;
|
||||
|
|
@ -163,7 +160,7 @@ export default definePlugin({
|
|||
settings,
|
||||
|
||||
flux: {
|
||||
VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: VoiceState[]; }) {
|
||||
VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: VoiceStateChangeEvent[]; }) {
|
||||
const myGuildId = SelectedGuildStore.getGuildId();
|
||||
const myChanId = SelectedChannelStore.getVoiceChannelId();
|
||||
const myId = UserStore.getCurrentUser().id;
|
||||
|
|
@ -195,7 +192,7 @@ export default definePlugin({
|
|||
|
||||
AUDIO_TOGGLE_SELF_MUTE() {
|
||||
const chanId = SelectedChannelStore.getVoiceChannelId()!;
|
||||
const s = VoiceStateStore.getVoiceStateForChannel(chanId) as VoiceState;
|
||||
const s = VoiceStateStore.getVoiceStateForChannel(chanId);
|
||||
if (!s) return;
|
||||
|
||||
const event = s.mute || s.selfMute ? "unmute" : "mute";
|
||||
|
|
@ -204,7 +201,7 @@ export default definePlugin({
|
|||
|
||||
AUDIO_TOGGLE_SELF_DEAF() {
|
||||
const chanId = SelectedChannelStore.getVoiceChannelId()!;
|
||||
const s = VoiceStateStore.getVoiceStateForChannel(chanId) as VoiceState;
|
||||
const s = VoiceStateStore.getVoiceStateForChannel(chanId);
|
||||
if (!s) return;
|
||||
|
||||
const event = s.deaf || s.selfDeaf ? "undeafen" : "deafen";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue