mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-51997] Fix potential errors when accessing calls store (#22960)
* Fix potential errors when accessing calls store * Fix typecheck
This commit is contained in:
parent
c98c43456e
commit
b5b4749da5
@ -50,12 +50,12 @@ function getDefaultChannelId(state: GlobalState) {
|
||||
return selectedPost.exists ? selectedPost.channel_id : getCurrentChannelId(state);
|
||||
}
|
||||
|
||||
function checkUserInCall(state: GlobalState, userId: string) {
|
||||
export function checkUserInCall(state: GlobalState, userId: string) {
|
||||
let isUserInCall = false;
|
||||
|
||||
const calls = getCalls(state);
|
||||
Object.keys(calls).forEach((channelId) => {
|
||||
const usersInCall = calls[channelId];
|
||||
const usersInCall = calls[channelId] || [];
|
||||
|
||||
for (const user of usersInCall) {
|
||||
if (user.id === userId) {
|
||||
|
@ -9,6 +9,7 @@ import {General} from 'mattermost-redux/constants';
|
||||
import {CustomStatusDuration} from '@mattermost/types/users';
|
||||
|
||||
import ProfilePopover from 'components/profile_popover/profile_popover';
|
||||
import {checkUserInCall} from 'components/profile_popover';
|
||||
|
||||
import Pluggable from 'plugins/pluggable';
|
||||
|
||||
@ -284,3 +285,52 @@ describe('components/ProfilePopover', () => {
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkUserInCall', () => {
|
||||
test('missing state', () => {
|
||||
expect(checkUserInCall({
|
||||
'plugins-com.mattermost.calls': {},
|
||||
} as any, 'userA')).toBe(false);
|
||||
});
|
||||
|
||||
test('call state missing', () => {
|
||||
expect(checkUserInCall({
|
||||
'plugins-com.mattermost.calls': {
|
||||
voiceConnectedProfiles: {
|
||||
channelID: null,
|
||||
},
|
||||
},
|
||||
} as any, 'userA')).toBe(false);
|
||||
});
|
||||
|
||||
test('user not in call', () => {
|
||||
expect(checkUserInCall({
|
||||
'plugins-com.mattermost.calls': {
|
||||
voiceConnectedProfiles: {
|
||||
channelID: [
|
||||
{
|
||||
id: 'userB',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
} as any, 'userA')).toBe(false);
|
||||
});
|
||||
|
||||
test('user in call', () => {
|
||||
expect(checkUserInCall({
|
||||
'plugins-com.mattermost.calls': {
|
||||
voiceConnectedProfiles: {
|
||||
channelID: [
|
||||
{
|
||||
id: 'userB',
|
||||
},
|
||||
{
|
||||
id: 'userA',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
} as any, 'userA')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
@ -74,7 +74,7 @@ export function getUsers(state: GlobalState): IDMappedObjects<UserProfile> {
|
||||
export function getCalls(state: GlobalState): Record<string, UserProfile[]> {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
return state[CALLS_PLUGIN].voiceConnectedProfiles;
|
||||
return state[CALLS_PLUGIN].voiceConnectedProfiles || {};
|
||||
}
|
||||
|
||||
export function getCallsConfig(state: GlobalState): CallsConfig {
|
||||
|
Loading…
Reference in New Issue
Block a user