-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
CallingRaisedHandsList.tsx
135 lines (126 loc) · 4.65 KB
/
CallingRaisedHandsList.tsx
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { Avatar, AvatarSize } from './Avatar';
import { ContactName } from './conversation/ContactName';
import type { ConversationsByDemuxIdType } from '../types/Calling';
import type { ServiceIdString } from '../types/ServiceId';
import type { LocalizerType } from '../types/Util';
import type { ConversationType } from '../state/ducks/conversations';
import { ModalHost } from './ModalHost';
import * as log from '../logging/log';
export type PropsType = {
readonly i18n: LocalizerType;
readonly onClose: () => void;
readonly onLowerMyHand: () => void;
readonly localDemuxId: number | undefined;
readonly conversationsByDemuxId: ConversationsByDemuxIdType;
readonly raisedHands: Set<number>;
readonly localHandRaised: boolean;
};
export function CallingRaisedHandsList({
i18n,
onClose,
onLowerMyHand,
localDemuxId,
conversationsByDemuxId,
raisedHands,
localHandRaised,
}: PropsType): JSX.Element | null {
const ourServiceId: ServiceIdString | undefined = localDemuxId
? conversationsByDemuxId.get(localDemuxId)?.serviceId
: undefined;
const participants = React.useMemo<Array<ConversationType>>(() => {
const serviceIds: Set<ServiceIdString> = new Set();
const conversations: Array<ConversationType> = [];
raisedHands.forEach(demuxId => {
const conversation = conversationsByDemuxId.get(demuxId);
if (!conversation) {
log.warn(
'CallingRaisedHandsList: Failed to get conversationsByDemuxId for demuxId',
{ demuxId }
);
return;
}
const { serviceId } = conversation;
if (serviceId) {
if (serviceIds.has(serviceId)) {
return;
}
serviceIds.add(serviceId);
}
conversations.push(conversation);
});
return conversations;
}, [raisedHands, conversationsByDemuxId]);
return (
<ModalHost
modalName="CallingRaisedHandsList"
moduleClassName="CallingRaisedHandsList"
onClose={onClose}
>
<div className="CallingRaisedHandsList module-calling-participants-list">
<div className="module-calling-participants-list__header">
<div className="module-calling-participants-list__title">
{i18n('icu:CallingRaisedHandsList__Title', {
count: participants.length,
})}
</div>
<button
type="button"
className="module-calling-participants-list__close"
onClick={onClose}
tabIndex={0}
aria-label={i18n('icu:close')}
/>
</div>
<ul className="module-calling-participants-list__list">
{participants.map((participant: ConversationType, index: number) => (
<li
className="module-calling-participants-list__contact"
key={participant.serviceId ?? index}
>
<div className="CallingRaisedHandsList__AvatarAndName module-calling-participants-list__avatar-and-name">
<Avatar
acceptedMessageRequest={participant.acceptedMessageRequest}
avatarPath={participant.avatarPath}
badge={undefined}
color={participant.color}
conversationType="direct"
i18n={i18n}
isMe={participant.isMe}
profileName={participant.profileName}
title={participant.title}
sharedGroupNames={participant.sharedGroupNames}
size={AvatarSize.THIRTY_TWO}
/>
{ourServiceId && participant.serviceId === ourServiceId ? (
<span className="module-calling-participants-list__name">
{i18n('icu:you')}
</span>
) : (
<ContactName
module="module-calling-participants-list__name"
title={participant.title}
/>
)}
</div>
{localHandRaised &&
ourServiceId &&
participant.serviceId === ourServiceId && (
<button
className="CallingRaisedHandsList__LowerMyHandLink"
type="button"
onClick={onLowerMyHand}
>
{i18n('icu:CallControls__RaiseHands--lower')}
</button>
)}
<div className="module-calling-participants-list__status-icon CallingRaisedHandsList__NameHandIcon" />
</li>
))}
</ul>
</div>
</ModalHost>
);
}