fix: resolve duplicate voice user in federated channel sidebar

Use origin-aware user ID resolution for optimistic voice add/remove
instead of always using the home instance ID. Adds getMyUserIdForOrigin
resolver (same pattern as getApiForOrigin) so joinVoiceChannel and
leaveVoice use the correct federated user ID. Also fixes WS reconnect
voice re-registration, invite URL for remote servers, and chatStore
early-load guard for unmapped channels.
This commit is contained in:
Jannis Braun
2026-03-07 14:33:37 +01:00
parent a9a68187b0
commit d18d9c51f7
7 changed files with 54 additions and 17 deletions
+7 -8
View File
@@ -1,6 +1,5 @@
import { useVoiceStore } from '../stores/voiceStore';
import { useAuthStore } from '../stores/authStore';
import { getChannelOrigin } from '../stores/serverStore';
import { getChannelOrigin, getMyUserIdForOrigin } from '../stores/serverStore';
import { wsSend } from '../hooks/useWebSocket';
/**
@@ -13,8 +12,6 @@ export function joinVoiceChannel(channelId: string): void {
const { currentVoiceChannelId, setCurrentVoiceChannel, addVoiceUser, removeVoiceUser } = useVoiceStore.getState();
if (currentVoiceChannelId === channelId) return;
const myId = useAuthStore.getState().user?.id;
// Leave old instance if switching cross-origin
if (currentVoiceChannelId) {
const oldOrigin = getChannelOrigin(currentVoiceChannelId);
@@ -22,12 +19,14 @@ export function joinVoiceChannel(channelId: string): void {
if (oldOrigin !== newOrigin) {
wsSend({ type: 'voice_leave' }, oldOrigin);
}
// Optimistic: immediately remove self from old channel
if (myId) removeVoiceUser(currentVoiceChannelId, myId);
// Optimistic: immediately remove self from old channel (using origin-aware ID)
const myOldId = getMyUserIdForOrigin(oldOrigin);
if (myOldId) removeVoiceUser(currentVoiceChannelId, myOldId);
}
setCurrentVoiceChannel(channelId);
// voice_join is now sent by useLiveKit after successful LiveKit connection
// Optimistic: immediately show self in new channel
if (myId) addVoiceUser(channelId, myId);
// Optimistic: immediately show self in new channel (using origin-aware ID)
const myNewId = getMyUserIdForOrigin(getChannelOrigin(channelId));
if (myNewId) addVoiceUser(channelId, myNewId);
}