From d172ff1881b281bd602cae1b6e679c5d6be771e0 Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Wed, 11 Oct 2023 10:48:19 -0600 Subject: [PATCH] [MM-51852] Update getProfilesInCalls selector (#24731) * Update getProfilesInCalls selector * Update tests --- .../src/components/profile_popover/index.ts | 19 +++++++----------- .../profile_popover/profile_popover.test.tsx | 20 +++++++++---------- .../src/selectors/entities/common.ts | 4 ++-- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/webapp/channels/src/components/profile_popover/index.ts b/webapp/channels/src/components/profile_popover/index.ts index 92c6a92dbe..8d1bca26b5 100644 --- a/webapp/channels/src/components/profile_popover/index.ts +++ b/webapp/channels/src/components/profile_popover/index.ts @@ -51,20 +51,15 @@ function getDefaultChannelId(state: GlobalState) { } export function checkUserInCall(state: GlobalState, userId: string) { - let isUserInCall = false; - - const profilesInCalls = getProfilesInCalls(state); - Object.keys(profilesInCalls).forEach((channelId) => { - const profiles = profilesInCalls[channelId] || []; - - for (const user of profiles) { - if (user.id === userId) { - isUserInCall = true; - break; + for (const profilesMap of Object.values(getProfilesInCalls(state))) { + for (const profile of Object.values(profilesMap || {})) { + if (profile?.id === userId) { + return true; } } - }); - return isUserInCall; + } + + return false; } function makeMapStateToProps() { diff --git a/webapp/channels/src/components/profile_popover/profile_popover.test.tsx b/webapp/channels/src/components/profile_popover/profile_popover.test.tsx index f5fb0c5918..c6a52ae151 100644 --- a/webapp/channels/src/components/profile_popover/profile_popover.test.tsx +++ b/webapp/channels/src/components/profile_popover/profile_popover.test.tsx @@ -294,7 +294,7 @@ describe('checkUserInCall', () => { test('call state missing', () => { expect(checkUserInCall({ 'plugins-com.mattermost.calls': { - voiceConnectedProfiles: { + profiles: { channelID: null, }, }, @@ -304,12 +304,12 @@ describe('checkUserInCall', () => { test('user not in call', () => { expect(checkUserInCall({ 'plugins-com.mattermost.calls': { - voiceConnectedProfiles: { - channelID: [ - { + profiles: { + channelID: { + sessionB: { id: 'userB', }, - ], + }, }, }, } as any, 'userA')).toBe(false); @@ -318,15 +318,15 @@ describe('checkUserInCall', () => { test('user in call', () => { expect(checkUserInCall({ 'plugins-com.mattermost.calls': { - voiceConnectedProfiles: { - channelID: [ - { + profiles: { + channelID: { + sessionB: { id: 'userB', }, - { + sessionA: { id: 'userA', }, - ], + }, }, }, } as any, 'userA')).toBe(true); diff --git a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/common.ts b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/common.ts index cf2568fa4d..225462be61 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/common.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/common.ts @@ -71,10 +71,10 @@ export function getUsers(state: GlobalState): IDMappedObjects { // Calls -export function getProfilesInCalls(state: GlobalState): Record { +export function getProfilesInCalls(state: GlobalState): Record> { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - return state[CALLS_PLUGIN].profiles || state[CALLS_PLUGIN].voiceConnectedProfiles || {}; + return state[CALLS_PLUGIN].profiles || {}; } export function getCallsConfig(state: GlobalState): CallsConfig {