@100mslive/roomkit-react 0.3.16-alpha.3 → 0.3.16-alpha.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
2
  import {
3
3
  selectHMSMessages,
4
4
  selectLocalPeerID,
5
+ selectPeerNameByID,
5
6
  selectSessionStore,
6
7
  selectUnreadHMSMessagesCount,
7
8
  useHMSStore,
@@ -14,6 +15,7 @@ import { Tooltip } from '../../../Tooltip';
14
15
  import IconButton from '../../IconButton';
15
16
  import { AnnotisedMessage } from '../Chat/ChatBody';
16
17
  import { useRoomLayoutConferencingScreen } from '../../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
18
+ import { useIsPeerBlacklisted } from '../hooks/useChatBlacklist';
17
19
  import { CHAT_MESSAGE_LIMIT, formatTime } from '../Chat/utils';
18
20
  import { SESSION_STORE_KEY } from '../../common/constants';
19
21
 
@@ -43,10 +45,29 @@ export const PIPChat = () => {
43
45
  const blacklistedMessageIDSet = new Set(blacklistedMessageIDs || []);
44
46
  return messages?.filter(message => message.type === 'chat' && !blacklistedMessageIDSet.has(message.id)) || [];
45
47
  }, [blacklistedMessageIDs, messages]);
48
+ const { enabled: isChatEnabled = true, updatedBy: chatStateUpdatedBy = '' } =
49
+ useHMSStore(selectSessionStore(SESSION_STORE_KEY.CHAT_STATE)) || {};
50
+ const isLocalPeerBlacklisted = useIsPeerBlacklisted({ local: true });
46
51
  const { elements } = useRoomLayoutConferencingScreen();
47
52
  const message_placeholder = elements?.chat?.message_placeholder || 'Send a message';
48
53
  const canSendChatMessages = !!elements?.chat?.public_chat_enabled || !!elements?.chat?.roles_whitelist?.length;
49
54
 
55
+ const getChatStatus = useCallback(() => {
56
+ if (isLocalPeerBlacklisted) return "You've been blocked from sending messages";
57
+ if (!isChatEnabled)
58
+ return `Chat has been paused by ${
59
+ chatStateUpdatedBy.peerId === localPeerID ? 'you' : chatStateUpdatedBy?.userName
60
+ }`;
61
+ return message_placeholder;
62
+ }, [
63
+ chatStateUpdatedBy.peerId,
64
+ chatStateUpdatedBy?.userName,
65
+ isChatEnabled,
66
+ isLocalPeerBlacklisted,
67
+ localPeerID,
68
+ message_placeholder,
69
+ ]);
70
+
50
71
  return (
51
72
  <div style={{ height: '100%' }}>
52
73
  <Box
@@ -55,7 +76,7 @@ export const PIPChat = () => {
55
76
  bg: '$surface_dim',
56
77
  overflowY: 'auto',
57
78
  // Subtracting height of footer
58
- h: canSendChatMessages ? 'calc(100% - 90px)' : '100%',
79
+ h: canSendChatMessages ? 'calc(100% - 87px)' : '100%',
59
80
  position: 'relative',
60
81
  }}
61
82
  >
@@ -108,16 +129,11 @@ export const PIPChat = () => {
108
129
  </Text>
109
130
  </Tooltip>
110
131
  )}
111
- {message.recipientRoles ? (
112
- <Text as="span" variant="sub2" css={{ color: '$on_surface_high', fontWeight: '$semiBold' }}>
113
- to {message.recipientRoles} (Group)
114
- </Text>
115
- ) : null}
116
- {message.recipientPeer ? (
117
- <Text as="span" variant="sub2" css={{ color: '$on_surface_high', fontWeight: '$semiBold' }}>
118
- (DM)
119
- </Text>
120
- ) : null}
132
+ <MessageTitle
133
+ localPeerID={localPeerID}
134
+ recipientPeer={message.recipientPeer}
135
+ recipientRoles={message.recipientRoles}
136
+ />
121
137
  </Flex>
122
138
 
123
139
  <Text
@@ -193,13 +209,16 @@ export const PIPChat = () => {
193
209
  <TextArea
194
210
  id="chat-input"
195
211
  maxLength={CHAT_MESSAGE_LIMIT}
196
- style={{ border: 'none', resize: 'none' }}
212
+ disabled={!isChatEnabled || isLocalPeerBlacklisted}
213
+ rows={1}
197
214
  css={{
198
215
  w: '100%',
199
216
  c: '$on_surface_high',
200
- padding: '0.25rem !important',
217
+ p: '0.75rem 0.75rem !important',
218
+ border: 'none',
219
+ resize: 'none',
201
220
  }}
202
- placeholder={message_placeholder}
221
+ placeholder={getChatStatus()}
203
222
  required
204
223
  autoComplete="off"
205
224
  aria-autocomplete="none"
@@ -207,6 +226,8 @@ export const PIPChat = () => {
207
226
 
208
227
  <IconButton
209
228
  id="send-btn"
229
+ disabled={!isChatEnabled || isLocalPeerBlacklisted}
230
+ title={getChatStatus()}
210
231
  css={{
211
232
  ml: 'auto',
212
233
  height: 'max-content',
@@ -223,3 +244,30 @@ export const PIPChat = () => {
223
244
  </div>
224
245
  );
225
246
  };
247
+
248
+ const MessageTitle = ({
249
+ recipientPeer,
250
+ recipientRoles,
251
+ localPeerID,
252
+ }: {
253
+ recipientPeer?: string;
254
+ recipientRoles?: string[];
255
+ localPeerID: string;
256
+ }) => {
257
+ const peerName = useHMSStore(selectPeerNameByID(recipientPeer));
258
+
259
+ return (
260
+ <>
261
+ {recipientRoles ? (
262
+ <Text as="span" variant="sub2" css={{ color: '$on_surface_high', fontWeight: '$semiBold' }}>
263
+ to {recipientRoles} (Group)
264
+ </Text>
265
+ ) : null}
266
+ {recipientPeer ? (
267
+ <Text as="span" variant="sub2" css={{ color: '$on_surface_high', fontWeight: '$semiBold' }}>
268
+ to {recipientPeer === localPeerID ? 'You' : peerName} (DM)
269
+ </Text>
270
+ ) : null}
271
+ </>
272
+ );
273
+ };
@@ -8,6 +8,6 @@ type PIPWindowProps = {
8
8
 
9
9
  export const PIPWindow = ({ pipWindow, children }: PIPWindowProps) => {
10
10
  pipWindow.document.body.style.margin = '0';
11
- pipWindow.document.body.style.overflowX = 'hidden';
11
+ pipWindow.document.body.style.overflow = 'clip';
12
12
  return createPortal(children, pipWindow.document.body);
13
13
  };
@@ -25,6 +25,8 @@ export const usePIPChat = () => {
25
25
  const pipChatInput = pipWindow.document.getElementById('chat-input') as HTMLTextAreaElement;
26
26
  const marker = pipWindow.document.getElementById('marker');
27
27
 
28
+ marker?.scrollIntoView({ block: 'end' });
29
+
28
30
  const observer = new IntersectionObserver(
29
31
  entries => {
30
32
  entries.forEach(entry => {