[MM-51997] Fix potential errors when accessing calls store (#22960)
* Fix potential errors when accessing calls store * Fix typecheck
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c98c43456e
Коммит
b5b4749da5
@@ -50,12 +50,12 @@ function getDefaultChannelId(state: GlobalState) {
|
|||||||
return selectedPost.exists ? selectedPost.channel_id : getCurrentChannelId(state);
|
return selectedPost.exists ? selectedPost.channel_id : getCurrentChannelId(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkUserInCall(state: GlobalState, userId: string) {
|
export function checkUserInCall(state: GlobalState, userId: string) {
|
||||||
let isUserInCall = false;
|
let isUserInCall = false;
|
||||||
|
|
||||||
const calls = getCalls(state);
|
const calls = getCalls(state);
|
||||||
Object.keys(calls).forEach((channelId) => {
|
Object.keys(calls).forEach((channelId) => {
|
||||||
const usersInCall = calls[channelId];
|
const usersInCall = calls[channelId] || [];
|
||||||
|
|
||||||
for (const user of usersInCall) {
|
for (const user of usersInCall) {
|
||||||
if (user.id === userId) {
|
if (user.id === userId) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {General} from 'mattermost-redux/constants';
|
|||||||
import {CustomStatusDuration} from '@mattermost/types/users';
|
import {CustomStatusDuration} from '@mattermost/types/users';
|
||||||
|
|
||||||
import ProfilePopover from 'components/profile_popover/profile_popover';
|
import ProfilePopover from 'components/profile_popover/profile_popover';
|
||||||
|
import {checkUserInCall} from 'components/profile_popover';
|
||||||
|
|
||||||
import Pluggable from 'plugins/pluggable';
|
import Pluggable from 'plugins/pluggable';
|
||||||
|
|
||||||
@@ -284,3 +285,52 @@ describe('components/ProfilePopover', () => {
|
|||||||
expect(wrapper).toMatchSnapshot();
|
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[]> {
|
export function getCalls(state: GlobalState): 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].voiceConnectedProfiles;
|
return state[CALLS_PLUGIN].voiceConnectedProfiles || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCallsConfig(state: GlobalState): CallsConfig {
|
export function getCallsConfig(state: GlobalState): CallsConfig {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user