fix: Fix multiple bugs with new authentication flow

This commit is contained in:
2026-06-07 15:04:21 +02:00
parent 9fc26b1ccf
commit 83456c018c
137 changed files with 4710 additions and 281 deletions

View File

@@ -42,7 +42,9 @@ import type {
import { NotificationAudioService, AppSound } from '../../core/services/notification-audio.service';
import { hasRoomBanForUser } from '../../domains/access-control';
import { RECONNECT_SOUND_GRACE_MS } from '../../core/constants';
import { VoiceSessionFacade } from '../../domains/voice-session';
import { VoiceSessionFacade, VoiceClientTakeoverService } from '../../domains/voice-session';
import { ClientInstanceService } from '../../core/platform/client-instance.service';
import { isVoiceOnAnotherClient } from '../../domains/voice-session/domain/logic/client-voice-session.rules';
import {
buildSignalingUser,
buildKnownUserExtras,
@@ -76,6 +78,8 @@ export class RoomStateSyncEffects {
private db = inject(DatabaseService);
private audioService = inject(NotificationAudioService);
private voiceSessionService = inject(VoiceSessionFacade);
private voiceClientTakeoverService = inject(VoiceClientTakeoverService);
private clientInstanceService = inject(ClientInstanceService);
/**
* Tracks user IDs we already know are in voice. Lives outside the
@@ -241,12 +245,18 @@ export class RoomStateSyncEffects {
const voiceEvent = {
...signalingMessage,
type: 'voice-state',
fromPeerId: signalingMessage.oderId ?? signalingMessage.fromUserId
fromPeerId: signalingMessage.oderId ?? signalingMessage.fromUserId,
voiceState: this.normalizeSignalingVoiceState(signalingMessage)
} as ChatEvent;
return this.handleVoiceOrScreenState(voiceEvent, allUsers, currentUser ?? null, 'voice');
}
case 'voice_client_takeover': {
this.voiceClientTakeoverService.releaseLocalVoiceForTakeover(currentUser ?? null);
return EMPTY;
}
case 'access_denied': {
if (isWrongServer(signalingMessage.serverId, viewedServerId))
return EMPTY;
@@ -479,7 +489,10 @@ export class RoomStateSyncEffects {
return EMPTY;
const existingUser = allUsers.find((user) => user.id === userId || user.oderId === userId);
const resolvedUserId = existingUser?.id ?? userId;
const userExists = !!existingUser;
const localClientInstanceId = this.clientInstanceService.getClientInstanceId();
const isCurrentUserEvent = !!currentUser && (currentUser.id === userId || currentUser.oderId === userId);
if (kind === 'voice') {
const vs = event.voiceState as Partial<VoiceState> | undefined;
@@ -503,8 +516,14 @@ export class RoomStateSyncEffects {
const wasInCurrentVoiceRoom = this.isSameVoiceRoom(existingUser?.voiceState, currentUser?.voiceState);
const mergedVoiceState = { ...existingUser?.voiceState, ...vs };
const isInCurrentVoiceRoom = this.isSameVoiceRoom(mergedVoiceState, currentUser?.voiceState);
const skipSelfPassiveSounds = isCurrentUserEvent
&& (isVoiceOnAnotherClient(
{ isConnected: mergedVoiceState.isConnected ?? false, clientInstanceId: mergedVoiceState.clientInstanceId },
localClientInstanceId
)
|| isVoiceOnAnotherClient(existingUser?.voiceState, localClientInstanceId));
if (weAreInVoice) {
if (weAreInVoice && !skipSelfPassiveSounds) {
const isReconnect = this.consumeRecentLeave(userId);
if (!isReconnect) {
@@ -537,7 +556,8 @@ export class RoomStateSyncEffects {
isMutedByAdmin: vs.isMutedByAdmin,
volume: vs.volume,
roomId: vs.roomId,
serverId: vs.serverId
serverId: vs.serverId,
clientInstanceId: vs.clientInstanceId
}
}
)
@@ -551,7 +571,7 @@ export class RoomStateSyncEffects {
actions.push(presenceRefreshAction);
}
actions.push(UsersActions.updateVoiceState({ userId, voiceState: vs }));
actions.push(UsersActions.updateVoiceState({ userId: resolvedUserId, voiceState: vs }));
return actions;
}
@@ -953,6 +973,26 @@ export class RoomStateSyncEffects {
// ── Internal helpers ───────────────────────────────────────────
private normalizeSignalingVoiceState(signalingMessage: RoomPresenceSignalingMessage): Partial<VoiceState> {
const nested = signalingMessage.voiceState;
if (nested && typeof nested === 'object') {
return nested as Partial<VoiceState>;
}
return {
isConnected: signalingMessage.isConnected === true,
isMuted: signalingMessage.isMuted === true,
isDeafened: signalingMessage.isDeafened === true,
isSpeaking: signalingMessage.isSpeaking === true,
roomId: typeof signalingMessage.roomId === 'string' ? signalingMessage.roomId : undefined,
serverId: typeof signalingMessage.serverId === 'string' ? signalingMessage.serverId : undefined,
clientInstanceId: typeof signalingMessage.clientInstanceId === 'string'
? signalingMessage.clientInstanceId
: undefined
};
}
private syncBansToLocalRoom(roomId: string, bans: BanEntry[]) {
return from(this.db.getBansForRoom(roomId)).pipe(
switchMap((localBans) => {