Skip to content

Commit 2cbdc52

Browse files
committed
fix: consider display avatar pref in video conf message
1 parent c8c8eaa commit 2cbdc52

File tree

4 files changed

+103
-28
lines changed

4 files changed

+103
-28
lines changed

packages/fuselage-ui-kit/src/blocks/VideoConferenceBlock/VideoConferenceBlock.tsx

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { VideoConferenceStatus } from '@rocket.chat/core-typings';
22
import {
33
useGoToRoom,
4+
useSetting,
45
useTranslation,
56
useUserId,
7+
useUserPreference,
68
} from '@rocket.chat/ui-contexts';
79
import type * as UiKit from '@rocket.chat/ui-kit';
810
import {
@@ -20,7 +22,7 @@ import {
2022
VideoConfMessageAction,
2123
} from '@rocket.chat/ui-video-conf';
2224
import type { MouseEventHandler, ReactElement } from 'react';
23-
import { useContext, memo } from 'react';
25+
import { useContext, memo, useCallback } from 'react';
2426

2527
import { UiKitContext } from '../..';
2628
import { useVideoConfDataStream } from './hooks/useVideoConfDataStream';
@@ -39,6 +41,8 @@ const VideoConferenceBlock = ({
3941
const surfaceType = useSurfaceType();
4042
const userId = useUserId();
4143
const goToRoom = useGoToRoom();
44+
const displayAvatars = useUserPreference<boolean>('displayAvatars');
45+
const showRealName = useSetting('UI_Use_Real_Name');
4246

4347
const { action, viewId = undefined, rid } = useContext(UiKitContext);
4448

@@ -97,6 +101,23 @@ const VideoConferenceBlock = ({
97101
}
98102
};
99103

104+
const getMessageFooterText = useCallback(
105+
(usersCount: number): string => {
106+
if (!displayAvatars) {
107+
return t('__usersCount__joined', {
108+
count: usersCount,
109+
});
110+
}
111+
112+
return usersCount > MAX_USERS
113+
? t('plus__usersCount__joined', {
114+
count: usersCount - MAX_USERS,
115+
})
116+
: t('joined');
117+
},
118+
[displayAvatars, t],
119+
);
120+
100121
if (result.isPending || result.isError) {
101122
// TODO: error handling
102123
return <VideoConfMessageSkeleton />;
@@ -105,6 +126,21 @@ const VideoConferenceBlock = ({
105126
const { data } = result;
106127
const isUserCaller = data.createdBy._id === userId;
107128

129+
const messageFooterText = getMessageFooterText(data.users.length);
130+
131+
const joinedUsernames = [...data.users]
132+
.splice(0, MAX_USERS)
133+
.map(({ name, username }) => (showRealName ? name : username))
134+
.join(', ');
135+
136+
const iconTitle =
137+
data.users.length > MAX_USERS
138+
? t('__usernames__and__count__more_joined', {
139+
usernames: joinedUsernames,
140+
count: data.users.length - MAX_USERS,
141+
})
142+
: t('__usernames__joined', { usernames: joinedUsernames });
143+
108144
const actions = (
109145
<VideoConfMessageActions>
110146
{data.discussionRid && (
@@ -147,13 +183,14 @@ const VideoConferenceBlock = ({
147183
{data.type !== 'direct' &&
148184
(data.users.length ? (
149185
<>
150-
<VideoConfMessageUserStack users={data.users} />
186+
<VideoConfMessageUserStack
187+
displayAvatars={displayAvatars}
188+
showRealName={showRealName}
189+
iconTitle={iconTitle}
190+
users={data.users}
191+
/>
151192
<VideoConfMessageFooterText>
152-
{data.users.length > MAX_USERS
153-
? t('__usersCount__member_joined', {
154-
usersCount: data.users.length - MAX_USERS,
155-
})
156-
: t('joined')}
193+
{messageFooterText}
157194
</VideoConfMessageFooterText>
158195
</>
159196
) : (
@@ -205,13 +242,14 @@ const VideoConferenceBlock = ({
205242
</VideoConfMessageButton>
206243
{Boolean(data.users.length) && (
207244
<>
208-
<VideoConfMessageUserStack users={data.users} />
245+
<VideoConfMessageUserStack
246+
displayAvatars={displayAvatars}
247+
showRealName={showRealName}
248+
users={data.users}
249+
iconTitle={iconTitle}
250+
/>
209251
<VideoConfMessageFooterText>
210-
{data.users.length > MAX_USERS
211-
? t('__usersCount__member_joined', {
212-
count: data.users.length - MAX_USERS,
213-
})
214-
: t('joined')}
252+
{messageFooterText}
215253
</VideoConfMessageFooterText>
216254
</>
217255
)}

packages/ui-video-conf/src/VideoConfMessage/VideoConfMessage.stories.tsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export default {
4545
const avatarUrl =
4646
'data:image/jpe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WEXeELxOzHSIPcmiiiunVlF2RNTpRkrs//Z';
4747

48+
const fakeUsers = Array.from({ length: 10 }).map((_, i) => ({
49+
username: `user${i}`,
50+
ts: new Date().toISOString(),
51+
name: `User ${i}`,
52+
_id: `id${i}`,
53+
avatarETag: '',
54+
}));
55+
4856
export const CallingDM: StoryFn<typeof VideoConfMessage> = () => (
4957
<VideoConfMessage>
5058
<VideoConfMessageRow>
@@ -94,8 +102,8 @@ export const CallOngoing: StoryFn<typeof VideoConfMessage> = () => (
94102
</VideoConfMessageRow>
95103
<VideoConfMessageFooter>
96104
<VideoConfMessageButton primary>Join</VideoConfMessageButton>
97-
<VideoConfMessageUserStack users={Array(3).fill('')} />
98-
<VideoConfMessageFooterText>Joined</VideoConfMessageFooterText>
105+
<VideoConfMessageUserStack users={fakeUsers} />
106+
<VideoConfMessageFooterText>joined</VideoConfMessageFooterText>
99107
</VideoConfMessageFooter>
100108
</VideoConfMessage>
101109
);
@@ -112,10 +120,29 @@ export const CallEnded: StoryFn<typeof VideoConfMessage> = () => (
112120
</VideoConfMessageActions>
113121
</VideoConfMessageRow>
114122
<VideoConfMessageFooter>
115-
<VideoConfMessageUserStack users={Array(3).fill('')} />
116-
<VideoConfMessageFooterText>Joined</VideoConfMessageFooterText>
123+
<VideoConfMessageUserStack users={fakeUsers} />
124+
<VideoConfMessageFooterText>joined</VideoConfMessageFooterText>
117125
</VideoConfMessageFooter>
118126
</VideoConfMessage>
119127
);
120128

121129
export const Loading: StoryFn<typeof VideoConfMessage> = () => <VideoConfMessageSkeleton />;
130+
131+
export const NoAvatars: StoryFn<typeof VideoConfMessage> = () => (
132+
<VideoConfMessage>
133+
<VideoConfMessageRow>
134+
<VideoConfMessageContent>
135+
<VideoConfMessageIcon variant='outgoing' />
136+
<VideoConfMessageText>Call ongoing</VideoConfMessageText>
137+
</VideoConfMessageContent>
138+
<VideoConfMessageActions>
139+
<VideoConfMessageAction aria-label='info' icon='info' />
140+
</VideoConfMessageActions>
141+
</VideoConfMessageRow>
142+
<VideoConfMessageFooter>
143+
<VideoConfMessageButton primary>Join</VideoConfMessageButton>
144+
<VideoConfMessageUserStack displayAvatars={false} users={fakeUsers} />
145+
<VideoConfMessageFooterText>{fakeUsers.length} joined</VideoConfMessageFooterText>
146+
</VideoConfMessageFooter>
147+
</VideoConfMessage>
148+
);

packages/ui-video-conf/src/VideoConfMessage/VideoConfMessageFooterText.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { AllHTMLAttributes, ReactElement } from 'react';
44
type VideoConfMessageFooterTextProps = Omit<AllHTMLAttributes<HTMLParagraphElement>, 'is'>;
55

66
const VideoConfMessageFooterText = ({ children, ...props }: VideoConfMessageFooterTextProps): ReactElement => (
7-
<Box {...props} is='p' fontScale='c1' mi={4}>
7+
<Box {...props} is='p' fontScale='micro' mi={4}>
88
{children}
99
</Box>
1010
);

packages/ui-video-conf/src/VideoConfMessage/VideoConfMessageUserStack.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1-
import type { IVideoConferenceUser, Serialized } from '@rocket.chat/core-typings';
2-
import { Avatar, Box } from '@rocket.chat/fuselage';
1+
import type { ISetting, IVideoConferenceUser, Serialized } from '@rocket.chat/core-typings';
2+
import { Avatar, Box, Icon } from '@rocket.chat/fuselage';
33
import { useUserAvatarPath } from '@rocket.chat/ui-contexts';
44
import { memo, type ReactElement } from 'react';
55

66
const MAX_USERS = 3;
77

8-
const VideoConfMessageUserStack = ({ users }: { users: Serialized<IVideoConferenceUser>[] }): ReactElement => {
8+
type VideoConfMessageUserStackProps = {
9+
users: Serialized<IVideoConferenceUser>[];
10+
displayAvatars?: boolean;
11+
iconTitle?: string;
12+
showRealName?: ISetting['value'];
13+
};
14+
15+
const VideoConfMessageUserStack = ({ users, showRealName, iconTitle, displayAvatars }: VideoConfMessageUserStackProps): ReactElement => {
916
const getUserAvatarPath = useUserAvatarPath();
1017

1118
return (
1219
<Box mi={4}>
13-
<Box display='flex' alignItems='center' mi='neg-x2'>
14-
{users.slice(0, MAX_USERS).map(({ username }, index) => (
15-
<Box mi={2} key={index}>
16-
<Avatar size='x28' alt={username || ''} data-tooltip={username} url={getUserAvatarPath(username as string)} />
17-
</Box>
18-
))}
19-
</Box>
20+
{displayAvatars && (
21+
<Box display='flex' alignItems='center' mi='neg-x2'>
22+
{users.slice(0, MAX_USERS).map(({ name, username }, index) => (
23+
<Box mi={2} key={index}>
24+
<Avatar size='x28' alt={username || ''} title={showRealName ? name : username} url={getUserAvatarPath(username as string)} />
25+
</Box>
26+
))}
27+
</Box>
28+
)}
29+
{!displayAvatars && <Icon size='x20' title={iconTitle} name='user' />}
2030
</Box>
2131
);
2232
};

0 commit comments

Comments
 (0)