-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Expand file tree
/
Copy pathuseUserMediaCallAction.ts
More file actions
56 lines (45 loc) · 1.64 KB
/
useUserMediaCallAction.ts
File metadata and controls
56 lines (45 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { isRoomFederated } from '@rocket.chat/core-typings';
import type { IRoom, IUser } from '@rocket.chat/core-typings';
import { useUserAvatarPath, useUserId, useUserSubscription, useUserCard, useUserRoom } from '@rocket.chat/ui-contexts';
import { usePeekMediaSessionState, useWidgetExternalControls } from '@rocket.chat/ui-voip';
import { useTranslation } from 'react-i18next';
import type { UserInfoAction } from '../useUserInfoActions';
export const useUserMediaCallAction = (user: Pick<IUser, '_id' | 'username' | 'name'>, rid: IRoom['_id']): UserInfoAction | undefined => {
const { t } = useTranslation();
const ownUserId = useUserId();
const { closeUserCard } = useUserCard();
const state = usePeekMediaSessionState();
const { toggleWidget } = useWidgetExternalControls();
const getAvatarUrl = useUserAvatarPath();
const currentSubscription = useUserSubscription(rid);
const room = useUserRoom(rid);
const blocked = currentSubscription?.blocked || currentSubscription?.blocker;
if (room && isRoomFederated(room)) {
return undefined;
}
if (state === 'unavailable') {
return undefined;
}
if (blocked) {
return undefined;
}
const disabled = state !== 'available';
if (user._id === ownUserId) {
return undefined;
}
const avatarUrl = user.username ? getAvatarUrl({ username: user.username }) : getAvatarUrl({ userId: user._id });
return {
type: 'communication',
title: t('Voice_call__user_', { user: user.name || user.username || '' }),
icon: 'phone',
onClick: () => {
closeUserCard();
toggleWidget({
userId: user._id,
displayName: user.name || user.username || '',
avatarUrl,
});
},
disabled,
};
};