From 7d981585bacadbc9e5eebb369d4dfe7ba8155e98 Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Thu, 2 Nov 2023 17:02:44 -0600 Subject: [PATCH] Fix client state on Desktop (#554) --- .../src/components/call_widget/component.tsx | 1 + webapp/src/index.tsx | 5 ++- webapp/src/reducers.ts | 32 +++++++++++++------ webapp/src/selectors.ts | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/webapp/src/components/call_widget/component.tsx b/webapp/src/components/call_widget/component.tsx index 9563db7b9..1c9f42017 100644 --- a/webapp/src/components/call_widget/component.tsx +++ b/webapp/src/components/call_widget/component.tsx @@ -434,6 +434,7 @@ export default class CallWidget extends React.PureComponent { if (this.props.global) { sendDesktopEvent('calls-joined-call', { callID: window.callsClient?.channelID, + sessionID: window.callsClient?.getSessionID(), }); } diff --git a/webapp/src/index.tsx b/webapp/src/index.tsx index c9fd0c1de..eaf58e1f8 100644 --- a/webapp/src/index.tsx +++ b/webapp/src/index.tsx @@ -529,7 +529,10 @@ export default class Plugin { } store.dispatch({ type: DESKTOP_WIDGET_CONNECTED, - data: {channelID: ev.data.message.callID}, + data: { + channel_id: ev.data.message.callID, + session_id: ev.data.message.sessionID, + }, }); } else if (ev.data?.type === 'calls-join-request') { // we can assume that we are already in a call, since the global widget sent this. diff --git a/webapp/src/reducers.ts b/webapp/src/reducers.ts index 60ba7fb7e..765fa4e73 100644 --- a/webapp/src/reducers.ts +++ b/webapp/src/reducers.ts @@ -145,26 +145,38 @@ const profiles = (state: profilesState = {}, action: profilesAction) => { } }; -type channelIDState = string | null; +type clientState = { + channelID: string; + sessionID: string; +} | null; -type channelIDAction = { +type clientStateAction = { type: string; data: { - channelID: string; - currentUserID: string; - userID: string; + channel_id: string; + session_id: string; }; } -// channelID is the channel ID of the call the current user is connected to. -const channelID = (state: channelIDState = null, action: channelIDAction) => { +// clientStateReducer holds the channel and session ID for the call the current user is connected to. +// This reducer is only needed by the Desktop app client to be aware that the user is +// connected through the global widget. +const clientStateReducer = (state: clientState = null, action: clientStateAction) => { switch (action.type) { case UNINIT: return null; case DESKTOP_WIDGET_CONNECTED: - return action.data.channelID; + return { + channelID: action.data.channel_id, + sessionID: action.data.session_id, + }; + case USER_LEFT: + if (action.data.session_id === state?.sessionID) { + return null; + } + return state; case CALL_END: - if (state === action.data.channelID) { + if (action.data.channel_id === state?.channelID) { return null; } return state; @@ -895,7 +907,7 @@ const dismissedCalls = (state: { [callID: string]: boolean } = {}, action: RingN export default combineReducers({ channels, - channelID, + clientStateReducer, profiles, // DEPRECATED - Needed to keep compatibility with older MM server diff --git a/webapp/src/selectors.ts b/webapp/src/selectors.ts index 86fdaee6a..9aa67f186 100644 --- a/webapp/src/selectors.ts +++ b/webapp/src/selectors.ts @@ -43,7 +43,7 @@ import {pluginId} from './manifest'; const pluginState = (state: GlobalState) => state['plugins-' + pluginId] || {}; export const channelIDForCurrentCall = (state: GlobalState): string => - pluginState(state).channelID || window.callsClient?.channelID || window.opener?.callsClient?.channelID || ''; + window.callsClient?.channelID || window.opener?.callsClient?.channelID || pluginState(state).clientStateReducer?.channelID || ''; export const channelForCurrentCall: (state: GlobalState) => Channel | undefined = createSelector(