Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(chat-web) add chat recipient picker (#16298)
Horatiu Muresan79dbc2d1eea5
diff --git a/lang/main.json b/lang/main.jsonindex 92e76dc1fa..084942e947 100644--- a/lang/main.json+++ b/lang/main.json@@ -112,6 +112,7 @@"disabled": "Sending chat messages is disabled.","enter": "Enter room","error": "Error: your message was not sent. Reason: {{error}}",+ "everyone": "Everyone","fieldPlaceHolder": "Aa","lobbyChatMessageTo": "Lobby chat message to {{recipient}}","message": "Message",diff --git a/react/features/base/ui/components/web/Select.tsx b/react/features/base/ui/components/web/Select.tsxindex b6ac0d3611..1289864a9e 100644--- a/react/features/base/ui/components/web/Select.tsx+++ b/react/features/base/ui/components/web/Select.tsx@@ -18,6 +18,11 @@ interface ISelectProps {*/className?: string;+ /**+ * Class name for additional styles for container.+ */+ containerClassName?: string;+/*** Whether or not the select is disabled.*/@@ -143,6 +148,7 @@ const useStyles = makeStyles()(theme => {const Select = ({bottomLabel,+ containerClassName,className,disabled,error,@@ -155,7 +161,7 @@ const Select = ({const isMobile = isMobileBrowser();return (- <div className = { classes.container }>+ <div className = { cx(classes.container, containerClassName) }>{label && <labelclassName = { cx(classes.label, isMobile && 'is-mobile') }htmlFor = { id } >diff --git a/react/features/chat/actionTypes.ts b/react/features/chat/actionTypes.tsindex 4b8bd690b9..7db6605b65 100644--- a/react/features/chat/actionTypes.ts+++ b/react/features/chat/actionTypes.ts@@ -163,3 +163,12 @@ export const SET_USER_CHAT_WIDTH = 'SET_USER_CHAT_WIDTH';* }*/export const SET_CHAT_IS_RESIZING = 'SET_CHAT_IS_RESIZING';++/**+ * The type of action sets the timestamp of the last private chat recipients list changed.+ *+ * {+ * type: NOTIFY_PRIVATE_RECIPIENTS_CHANGED+ * }+ */+ export const NOTIFY_PRIVATE_RECIPIENTS_CHANGED = 'NOTIFY_PRIVATE_RECIPIENTS_CHANGED';diff --git a/react/features/chat/actions.any.ts b/react/features/chat/actions.any.tsindex 146572a384..7e9d7a53ce 100644--- a/react/features/chat/actions.any.ts+++ b/react/features/chat/actions.any.ts@@ -1,6 +1,6 @@import { IStore } from '../app/types';import { getCurrentConference } from '../base/conference/functions';-import { getLocalParticipant } from '../base/participants/functions';+import { getLocalParticipant, getParticipantById } from '../base/participants/functions';import { IParticipant } from '../base/participants/types';import { LOBBY_CHAT_INITIALIZED } from '../lobby/constants';@@ -10,6 +10,7 @@ import {CLEAR_MESSAGES,CLOSE_CHAT,EDIT_MESSAGE,+ NOTIFY_PRIVATE_RECIPIENTS_CHANGED,OPEN_CHAT,REMOVE_LOBBY_CHAT_PARTICIPANT,SEND_MESSAGE,@@ -170,6 +171,25 @@ export function setPrivateMessageRecipient(participant?: Object) {};}+/**+ * Initiates the sending of a private message to the supplied participantId.+ *+ * @param {string} participantId - The participant id to set the recipient to.+ * @returns {{+* participant: IParticipant,+* type: SET_PRIVATE_MESSAGE_RECIPIENT+* }}+*/+export function setPrivateMessageRecipientById(participantId: string) {+ return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {+ const participant = getParticipantById(getState(), participantId);++ if (participant) {+ dispatch(setPrivateMessageRecipient(participant));+ }+ };+}+/*** Set the value of the currently focused tab.*@@ -252,6 +272,22 @@ export function setLobbyChatActiveState(value: boolean) {};}+/**+ * Notifies the private chat recipients list changed.+ *+ * @returns {Object}+ */+export function notifyPrivateRecipientsChanged() {+ return (dispatch: IStore['dispatch']) => {+ const timestamp = Date.now();++ return dispatch({+ type: NOTIFY_PRIVATE_RECIPIENTS_CHANGED,+ payload: timestamp+ });+ };+}+/*** Removes lobby type messages.*diff --git a/react/features/chat/components/web/Chat.tsx b/react/features/chat/components/web/Chat.tsxindex faf9610aac..796d924be0 100644--- a/react/features/chat/components/web/Chat.tsx+++ b/react/features/chat/components/web/Chat.tsx@@ -1,20 +1,29 @@import { throttle } from 'lodash-es';-import React, { useCallback, useEffect, useState } from 'react';+import React, { useCallback, useEffect, useMemo, useState } from 'react';import { connect, useSelector } from 'react-redux';import { makeStyles } from 'tss-react/mui';import { IReduxState } from '../../../app/types';import { translate } from '../../../base/i18n/functions';import { IconInfo, IconMessage, IconShareDoc, IconSubtitles } from '../../../base/icons/svg';-import { getLocalParticipant } from '../../../base/participants/functions';+import { getLocalParticipant, getRemoteParticipants } from '../../../base/participants/functions';+import Select from '../../../base/ui/components/web/Select';import Tabs from '../../../base/ui/components/web/Tabs';import { arePollsDisabled } from '../../../conference/functions.any';import FileSharing from '../../../file-sharing/components/web/FileSharing';import { isFileSharingEnabled } from '../../../file-sharing/functions.any';import PollsPane from '../../../polls/components/web/PollsPane';import { isCCTabEnabled } from '../../../subtitles/functions.any';-import { sendMessage, setChatIsResizing, setFocusedTab, setUserChatWidth, toggleChat } from '../../actions.web';-import { CHAT_SIZE, ChatTabs, SMALL_WIDTH_THRESHOLD } from '../../constants';+import {+ sendMessage,+ setChatIsResizing,+ setFocusedTab,+ setPrivateMessageRecipient,+ setPrivateMessageRecipientById,+ setUserChatWidth,+ toggleChat+} from '../../actions.web';+import { CHAT_SIZE, ChatTabs, OPTION_GROUPCHAT, SMALL_WIDTH_THRESHOLD } from '../../constants';import { getChatMaxSize } from '../../functions';import { IChatProps as AbstractProps } from '../../types';@@ -216,6 +225,10 @@ const useStyles = makeStyles<{ _isResizing: boolean; width: number; }>()((theme,height: '100px',width: '3px',borderRadius: '1px'+ },++ privateMessageRecipientsList: {+ padding: '0 16px 5px'}};});@@ -245,6 +258,34 @@ const Chat = ({const [ mousePosition, setMousePosition ] = useState<number | null>(null);const [ dragChatWidth, setDragChatWidth ] = useState<number | null>(null);const maxChatWidth = useSelector(getChatMaxSize);+ const notifyTimestamp = useSelector((state: IReduxState) =>+ state['features/chat'].notifyPrivateRecipientsChangedTimestamp+ );+ const {+ defaultRemoteDisplayName = 'Fellow Jitster'+ } = useSelector((state: IReduxState) => state['features/base/config']);+ const privateMessageRecipient = useSelector((state: IReduxState) => state['features/chat'].privateMessageRecipient);+ const participants = useSelector(getRemoteParticipants);++ const options = useMemo(() => {+ const o = Array.from(participants?.values() || [])+ .filter(p => !p.fakeParticipant)+ .map(p => {+ return {+ value: p.id,+ label: p.name ?? defaultRemoteDisplayName+ };+ });++ o.sort((a, b) => a.label.localeCompare(b.label));++ o.unshift({+ label: t('chat.everyone'),+ value: OPTION_GROUPCHAT+ });++ return o;+ }, [ participants, defaultRemoteDisplayName, t, notifyTimestamp ]);/*** Handles mouse down on the drag handle.@@ -376,6 +417,17 @@ const Chat = ({dispatch(setFocusedTab(id as ChatTabs));}, [ dispatch ]);++ const onSelectedRecipientChange = useCallback((e: React.ChangeEvent<HTMLSelectElement>) => {+ const selected = e.target.value;++ if (selected === OPTION_GROUPCHAT) {+ dispatch(setPrivateMessageRecipient());+ } else {+ dispatch(setPrivateMessageRecipientById(selected));+ }+ }, []);+/*** Returns a React Element for showing chat messages and a form to send new* chat messages.@@ -403,6 +455,12 @@ const Chat = ({<MessageContainermessages = { _messages } /><MessageRecipient />+ <Select+ containerClassName = { cx(classes.privateMessageRecipientsList) }+ id = 'select-chat-recipient'+ onChange = { onSelectedRecipientChange }+ options = { options }+ value = { privateMessageRecipient?.id || OPTION_GROUPCHAT } /><ChatInputonSend = { onSendMessage } /></div>diff --git a/react/features/chat/constants.ts b/react/features/chat/constants.tsindex 21d23310ea..f1285c0b1c 100644--- a/react/features/chat/constants.ts+++ b/react/features/chat/constants.ts@@ -55,3 +55,5 @@ export const TIMESTAMP_FORMAT = 'H:mm';* The namespace for system messages.*/export const MESSAGE_TYPE_SYSTEM = 'system_chat_message';++export const OPTION_GROUPCHAT = 'groupchat';diff --git a/react/features/chat/middleware.ts b/react/features/chat/middleware.tsindex 0b4abf6e75..52583fd127 100644--- a/react/features/chat/middleware.ts+++ b/react/features/chat/middleware.ts@@ -15,11 +15,13 @@ import {JitsiConferenceErrors,JitsiConferenceEvents} from '../base/lib-jitsi-meet';+import { PARTICIPANT_JOINED, PARTICIPANT_LEFT, PARTICIPANT_UPDATED } from '../base/participants/actionTypes';import {getLocalParticipant,getParticipantById,getParticipantDisplayName} from '../base/participants/functions';+import { IParticipant } from '../base/participants/types';import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';import StateListenerRegistry from '../base/redux/StateListenerRegistry';import { playSound, registerSound, unregisterSound } from '../base/sounds/actions';@@ -43,7 +45,14 @@ import {SEND_REACTION,SET_FOCUSED_TAB} from './actionTypes';-import { addMessage, addMessageReaction, clearMessages, closeChat, setPrivateMessageRecipient } from './actions.any';+import {+ addMessage,+ addMessageReaction,+ clearMessages,+ closeChat,+ notifyPrivateRecipientsChanged,+ setPrivateMessageRecipient+} from './actions.any';import { ChatPrivacyDialog } from './components';import {ChatTabs,@@ -198,6 +207,19 @@ MiddlewareRegistry.register(store => next => action => {break;}+ case PARTICIPANT_JOINED:+ case PARTICIPANT_LEFT:+ case PARTICIPANT_UPDATED: {+ if (_shouldNotifyPrivateRecipientsChanged(store, action)) {+ const result = next(action);++ dispatch(notifyPrivateRecipientsChanged());++ return result;+ }+ break;+ }+case SEND_MESSAGE: {const state = store.getState();const conference = getCurrentConference(state);@@ -303,6 +325,27 @@ StateListenerRegistry.register(});+/**+ * Checks whether a notification for private chat recipients is needed.+ *+ * @param {IStore} store - The redux store.+ * @param {{ participant: IParticipant, type: string }} action - The action.+ * @returns {boolean}+ */+function _shouldNotifyPrivateRecipientsChanged(+ store: IStore, action: { participant: IParticipant; type: string; }+) {+ const { type, participant } = action;++ if ([ PARTICIPANT_LEFT, PARTICIPANT_JOINED ].includes(type)) {+ return true;+ }++ const { id, name } = participant;++ return name !== getParticipantDisplayName(store, id);+}+/*** Registers listener for {@link JitsiConferenceEvents.MESSAGE_RECEIVED} that* will perform various chat related activities.diff --git a/react/features/chat/reducer.ts b/react/features/chat/reducer.tsindex 791f5905ae..197f30308d 100644--- a/react/features/chat/reducer.ts+++ b/react/features/chat/reducer.ts@@ -9,6 +9,7 @@ import {CLEAR_MESSAGES,CLOSE_CHAT,EDIT_MESSAGE,+ NOTIFY_PRIVATE_RECIPIENTS_CHANGED,OPEN_CHAT,REMOVE_LOBBY_CHAT_PARTICIPANT,SET_CHAT_IS_RESIZING,@@ -26,6 +27,7 @@ const DEFAULT_STATE = {groupChatWithPermissions: false,isOpen: false,messages: [],+ notifyPrivateRecipientsChangedTimestamp: undefined,reactions: {},nbUnreadMessages: 0,privateMessageRecipient: undefined,@@ -52,6 +54,7 @@ export interface IChatState {} | ILocalParticipant;messages: IMessage[];nbUnreadMessages: number;+ notifyPrivateRecipientsChangedTimestamp?: number;privateMessageRecipient?: IParticipant | IVisitorChatParticipant;width: {current: number;@@ -262,6 +265,11 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, acisResizing: action.resizing};}+ case NOTIFY_PRIVATE_RECIPIENTS_CHANGED:+ return {+ ...state,+ notifyPrivateRecipientsChangedTimestamp: action.payload+ };}return state;