fix: vcNarratorCustom user leave voice event filtering bug (#671)
* fix(vcNarratorCustom): voice state event filtering is stricter now and has a guard against false positive userleave events * refactor(vcNarratorCustom): remove unused audio toggle functions for self-mute and self-deaf, they're not wired into the menu anyways. I forgot about them cause i just use discords built in mute/deafen sound for my own audio * fix(vcNarratorCustom): ensure voice state snapshot updates only occur if myChanId is defined as an extra guard
This commit is contained in:
parent
6e85d45c1a
commit
08174fb27e
1 changed files with 19 additions and 21 deletions
|
|
@ -938,9 +938,19 @@ export default definePlugin({
|
|||
|
||||
flux: {
|
||||
async VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: VoiceState[]; }) {
|
||||
const myGuildId = SelectedGuildStore.getGuildId();
|
||||
const myChanId = SelectedChannelStore.getVoiceChannelId();
|
||||
const myId = UserStore.getCurrentUser().id;
|
||||
const myGuildId = SelectedGuildStore.getGuildId();
|
||||
const myVoiceState = VoiceStateStore.getVoiceStateForUser(myId) as VoiceState | undefined;
|
||||
let myChanId = myVoiceState?.channelId;
|
||||
if (!myChanId) {
|
||||
const selectedChanId = SelectedChannelStore.getVoiceChannelId();
|
||||
if (selectedChanId) {
|
||||
const states = VoiceStateStore.getVoiceStatesForChannel?.(selectedChanId) as Record<string, VoiceState> | undefined;
|
||||
if (states?.[myId]?.channelId === selectedChanId) {
|
||||
myChanId = selectedChanId;
|
||||
}
|
||||
}
|
||||
}
|
||||
const filterMode = settings.store.stateChangeFilterMode ?? "off";
|
||||
const filterList = parseStateChangeFilterList(settings.store.stateChangeFilterList);
|
||||
const allowStateChange = (targetId: string, isSelf: boolean) => {
|
||||
|
|
@ -972,6 +982,7 @@ export default definePlugin({
|
|||
let { oldChannelId } = state;
|
||||
|
||||
const isMe = userId === myId;
|
||||
if (!isMe && !myChanId) continue;
|
||||
if (isMe && channelId !== myLastChannelId) {
|
||||
oldChannelId = myLastChannelId;
|
||||
myLastChannelId = channelId ?? undefined;
|
||||
|
|
@ -981,10 +992,12 @@ export default definePlugin({
|
|||
if (!isMe && !affectsMyChannel) continue;
|
||||
|
||||
// Keep snapshots in sync for join/leave/move without announcing state changes.
|
||||
if (oldChannelId !== myChanId && channelId === myChanId) {
|
||||
voiceStateSnapshot.set(userId, normalizeState(state));
|
||||
} else if (oldChannelId === myChanId && channelId !== myChanId) {
|
||||
voiceStateSnapshot.delete(userId);
|
||||
if (myChanId) {
|
||||
if (oldChannelId !== myChanId && channelId === myChanId) {
|
||||
voiceStateSnapshot.set(userId, normalizeState(state));
|
||||
} else if (oldChannelId === myChanId && channelId !== myChanId) {
|
||||
voiceStateSnapshot.delete(userId);
|
||||
}
|
||||
}
|
||||
|
||||
// Join/leave/move announcements (existing behavior)
|
||||
|
|
@ -1047,21 +1060,6 @@ export default definePlugin({
|
|||
}
|
||||
},
|
||||
|
||||
AUDIO_TOGGLE_SELF_MUTE() {
|
||||
const chanId = SelectedChannelStore.getVoiceChannelId()!;
|
||||
const s = VoiceStateStore.getVoiceStateForChannel(
|
||||
chanId
|
||||
) as VoiceState;
|
||||
if (!s) return;
|
||||
},
|
||||
|
||||
AUDIO_TOGGLE_SELF_DEAF() {
|
||||
const chanId = SelectedChannelStore.getVoiceChannelId()!;
|
||||
const s = VoiceStateStore.getVoiceStateForChannel(
|
||||
chanId
|
||||
) as VoiceState;
|
||||
if (!s) return;
|
||||
},
|
||||
},
|
||||
|
||||
settingsAboutComponent({ tempSettings: s }: { tempSettings?: any; }) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue