This commit is contained in:
2025-05-15 05:20:01 +03:00
parent 623521f3b4
commit 21a05dd202
70 changed files with 4663 additions and 161 deletions

View File

@@ -0,0 +1,39 @@
// ~/store/active-voice-channel.ts
import { create } from 'zustand';
import type { Uuid } from '~/lib/api/types';
interface ActiveVoiceChannelState {
serverId: Uuid | null;
channelId: Uuid | null;
// User's explicit intent to be in voice, helps differentiate between just selecting a channel and actually joining
isVoiceActive: boolean;
setActiveVoiceChannel: (serverId: Uuid | null, channelId: Uuid | null) => void;
toggleVoiceActivation: (activate: boolean) => void; // To explicitly join/leave voice for the selected channel
}
export const useActiveVoiceChannelStore = create<ActiveVoiceChannelState>((set, get) => ({
serverId: null,
channelId: null,
isVoiceActive: false,
setActiveVoiceChannel: (serverId, channelId) => {
const current = get();
// If changing channels, implicitly deactivate voice from the old one.
// The manager will then pick up the new channel and wait for isVoiceActive.
if (current.channelId !== channelId && current.isVoiceActive) {
set({ serverId, channelId, isVoiceActive: false }); // User needs to explicitly activate new channel
} else {
set({ serverId, channelId });
}
console.log(`ActiveVoiceChannel: Selected Server: ${serverId}, Channel: ${channelId}`);
},
toggleVoiceActivation: (activate) => {
const { serverId, channelId } = get();
if (activate && (!serverId || !channelId)) {
console.warn("ActiveVoiceChannel: Cannot activate voice without a selected server/channel.");
set({ isVoiceActive: false });
return;
}
set({ isVoiceActive: activate });
console.log(`ActiveVoiceChannel: Voice activation set to ${activate} for ${serverId}/${channelId}`);
},
}));