[MM-51852] Update getProfilesInCalls selector (#24731)
* Update getProfilesInCalls selector * Update tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
77ee4d93b7
Коммит
d172ff1881
@@ -51,20 +51,15 @@ function getDefaultChannelId(state: GlobalState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function checkUserInCall(state: GlobalState, userId: string) {
|
export function checkUserInCall(state: GlobalState, userId: string) {
|
||||||
let isUserInCall = false;
|
for (const profilesMap of Object.values(getProfilesInCalls(state))) {
|
||||||
|
for (const profile of Object.values(profilesMap || {})) {
|
||||||
const profilesInCalls = getProfilesInCalls(state);
|
if (profile?.id === userId) {
|
||||||
Object.keys(profilesInCalls).forEach((channelId) => {
|
return true;
|
||||||
const profiles = profilesInCalls[channelId] || [];
|
|
||||||
|
|
||||||
for (const user of profiles) {
|
|
||||||
if (user.id === userId) {
|
|
||||||
isUserInCall = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return isUserInCall;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeMapStateToProps() {
|
function makeMapStateToProps() {
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ describe('checkUserInCall', () => {
|
|||||||
test('call state missing', () => {
|
test('call state missing', () => {
|
||||||
expect(checkUserInCall({
|
expect(checkUserInCall({
|
||||||
'plugins-com.mattermost.calls': {
|
'plugins-com.mattermost.calls': {
|
||||||
voiceConnectedProfiles: {
|
profiles: {
|
||||||
channelID: null,
|
channelID: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -304,12 +304,12 @@ describe('checkUserInCall', () => {
|
|||||||
test('user not in call', () => {
|
test('user not in call', () => {
|
||||||
expect(checkUserInCall({
|
expect(checkUserInCall({
|
||||||
'plugins-com.mattermost.calls': {
|
'plugins-com.mattermost.calls': {
|
||||||
voiceConnectedProfiles: {
|
profiles: {
|
||||||
channelID: [
|
channelID: {
|
||||||
{
|
sessionB: {
|
||||||
id: 'userB',
|
id: 'userB',
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as any, 'userA')).toBe(false);
|
} as any, 'userA')).toBe(false);
|
||||||
@@ -318,15 +318,15 @@ describe('checkUserInCall', () => {
|
|||||||
test('user in call', () => {
|
test('user in call', () => {
|
||||||
expect(checkUserInCall({
|
expect(checkUserInCall({
|
||||||
'plugins-com.mattermost.calls': {
|
'plugins-com.mattermost.calls': {
|
||||||
voiceConnectedProfiles: {
|
profiles: {
|
||||||
channelID: [
|
channelID: {
|
||||||
{
|
sessionB: {
|
||||||
id: 'userB',
|
id: 'userB',
|
||||||
},
|
},
|
||||||
{
|
sessionA: {
|
||||||
id: 'userA',
|
id: 'userA',
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as any, 'userA')).toBe(true);
|
} as any, 'userA')).toBe(true);
|
||||||
|
|||||||
@@ -71,10 +71,10 @@ export function getUsers(state: GlobalState): IDMappedObjects<UserProfile> {
|
|||||||
|
|
||||||
// Calls
|
// 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
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return state[CALLS_PLUGIN].profiles || state[CALLS_PLUGIN].voiceConnectedProfiles || {};
|
return state[CALLS_PLUGIN].profiles || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCallsConfig(state: GlobalState): CallsConfig {
|
export function getCallsConfig(state: GlobalState): CallsConfig {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user