[MM-51852] Update getProfilesInCalls selector (#24731)

* Update getProfilesInCalls selector

* Update tests
Этот коммит содержится в:
Claudio Costa
2023-10-11 10:48:19 -06:00
коммит произвёл GitHub
родитель 77ee4d93b7
Коммит d172ff1881
3 изменённых файлов: 19 добавлений и 24 удалений

Просмотреть файл

@@ -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() {

Просмотреть файл

@@ -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);

Просмотреть файл

@@ -71,10 +71,10 @@ export function getUsers(state: GlobalState): IDMappedObjects<UserProfile> {
// Calls
export function getProfilesInCalls(state: GlobalState): Record<string, UserProfile[]> {
export function getProfilesInCalls(state: GlobalState): Record<string, Record<string, UserProfile>> {
// 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 {