From f44add983541183a1512df9f6b86d5dde2e1d1d4 Mon Sep 17 00:00:00 2001 From: bennybrainless <242895261+bennybrainless@users.noreply.github.com> Date: Sat, 22 Nov 2025 00:10:33 -0600 Subject: [PATCH] Handle new voice participants on updates --- discord/src/stores/callStore.ts | 49 ++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/discord/src/stores/callStore.ts b/discord/src/stores/callStore.ts index 65f26b6..992d77f 100644 --- a/discord/src/stores/callStore.ts +++ b/discord/src/stores/callStore.ts @@ -148,32 +148,61 @@ export const useCallStore = create((set, get) => { set((state) => { if (!state.callStatus) return {}; - const participants = state.callStatus.participants.map( + const payload = event.payload as { + userId?: string; + username?: string; + profileUrl?: string; + isSpeaking?: boolean; + isMuted?: boolean; + isDeafened?: boolean; + }; + + if (!payload.userId) return {}; + + const participantExists = state.callStatus.participants.some( + (participant) => participant.id === payload.userId + ); + + const updatedParticipants = state.callStatus.participants.map( (participant) => - participant.id === event.payload.userId + participant.id === payload.userId ? { ...participant, - isDeafened: event.payload.isDeafened, - isMuted: event.payload.isMuted, + isDeafened: payload.isDeafened, + isMuted: payload.isMuted, } : participant ); + const participants = participantExists + ? updatedParticipants + : [ + ...updatedParticipants, + { + id: payload.userId, + username: payload.username ?? payload.userId, + profileUrl: payload.profileUrl, + isSpeaking: payload.isSpeaking ?? false, + isMuted: payload.isMuted ?? false, + isDeafened: payload.isDeafened ?? false, + }, + ]; + const shouldUpdateUser = - state.callStatus.user?.id === event.payload.userId || - state.selfUserId === event.payload.userId; + state.callStatus.user?.id === payload.userId || + state.selfUserId === payload.userId; const nextUser = shouldUpdateUser ? state.callStatus.user && - state.callStatus.user.id === event.payload.userId + state.callStatus.user.id === payload.userId ? { ...state.callStatus.user, - isDeafened: event.payload.isDeafened, - isMuted: event.payload.isMuted, + isDeafened: payload.isDeafened, + isMuted: payload.isMuted, } : participants.find( - (participant) => participant.id === event.payload.userId + (participant) => participant.id === payload.userId ) ?? state.callStatus.user : state.callStatus.user;