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(visitors): Private messages to main participants.
Hristo Terezovcb621f8e32da
diff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.tsindex c1c19692a4..8ecbe0a1d0 100644--- a/react/features/base/config/configType.ts+++ b/react/features/base/config/configType.ts@@ -553,7 +553,7 @@ export interface IConfig {disableDemote?: boolean;disableGrantModerator?: boolean;disableKick?: boolean;- disablePrivateChat?: 'all' | 'allow-moderator-chat';+ disablePrivateChat?: 'all' | 'allow-moderator-chat' | 'disable-visitor-chat';disabled?: boolean;};replaceParticipant?: string;diff --git a/react/features/base/participants/functions.ts b/react/features/base/participants/functions.tsindex eb4ee021a2..3d91aee4d7 100644--- a/react/features/base/participants/functions.ts+++ b/react/features/base/participants/functions.ts@@ -2,10 +2,12 @@import { getGravatarURL } from '@jitsi/js-utils/avatar';import { IReduxState, IStore } from '../../app/types';+import { isVisitorChatParticipant } from '../../chat/functions';import { isStageFilmstripAvailable } from '../../filmstrip/functions';import { isAddPeopleEnabled, isDialOutEnabled } from '../../invite/functions';import { toggleShareDialog } from '../../share-room/actions';import { iAmVisitor } from '../../visitors/functions';+import { IVisitorChatParticipant } from '../../visitors/types';import { IStateful } from '../app/types';import { GRAVATAR_BASE_URL } from '../avatar/constants';import { isCORSAvatarURL } from '../avatar/functions';@@ -827,18 +829,28 @@ export const setShareDialogVisiblity = (addPeopleFeatureEnabled: boolean, dispat/*** Checks if private chat is enabled for the given participant.*- * @param {IParticipant|undefined} participant - The participant to check.+ * @param {IParticipant|IVisitorChatParticipant|undefined} participant - The participant to check.* @param {IReduxState} state - The Redux state.* @returns {boolean} - True if private chat is enabled, false otherwise.*/-export function isPrivateChatEnabled(participant: IParticipant | undefined, state: IReduxState) {+export function isPrivateChatEnabled(participant: IParticipant | IVisitorChatParticipant | undefined, state: IReduxState) {const { remoteVideoMenu = {} } = state['features/base/config'];const { disablePrivateChat } = remoteVideoMenu;- if (participant?.local || state['features/visitors'].iAmVisitor || disablePrivateChat === 'all') {+ if ((!isVisitorChatParticipant(participant) && participant?.local) || disablePrivateChat === 'all') {return false;}+ if (disablePrivateChat === 'disable-visitor-chat') {+ // Block if the participant we're trying to message is a visitor+ // OR if the local user is a visitor+ if (isVisitorChatParticipant(participant) || iAmVisitor(state)) {+ return false;+ }++ return true; // should allow private chat for other participants+ }+if (disablePrivateChat === 'allow-moderator-chat') {return isLocalParticipantModerator(state) || isParticipantModerator(participant);}diff --git a/react/features/chat/components/AbstractChatPrivacyDialog.tsx b/react/features/chat/components/AbstractChatPrivacyDialog.tsxindex 252d83047b..9d791be07c 100644--- a/react/features/chat/components/AbstractChatPrivacyDialog.tsx+++ b/react/features/chat/components/AbstractChatPrivacyDialog.tsx@@ -4,6 +4,7 @@ import { WithTranslation } from 'react-i18next';import { IReduxState, IStore } from '../../app/types';import { getParticipantById } from '../../base/participants/functions';import { IParticipant } from '../../base/participants/types';+import { IVisitorChatParticipant } from '../../visitors/types';import { sendMessage, setPrivateMessageRecipient } from '../actions';interface IProps extends WithTranslation {@@ -23,6 +24,16 @@ interface IProps extends WithTranslation {*/_participant?: IParticipant;+ /**+ * The display name of the visitor (if applicable).+ */+ displayName?: string;++ /**+ * Whether the message is from a visitor.+ */+ isFromVisitor?: boolean;+/*** The message that is about to be sent.*/@@ -67,9 +78,21 @@ export class AbstractChatPrivacyDialog extends PureComponent<IProps> {* @returns {void}*/_onSendPrivateMessage() {- const { message, _onSendMessage, _onSetMessageRecipient, _participant } = this.props;+ const { message, _onSendMessage, _onSetMessageRecipient, _participant, isFromVisitor, displayName, participantID } = this.props;++ if (isFromVisitor) {+ // For visitors, create a participant object since they don't exist in the main participant list+ const visitorParticipant = {+ id: participantID,+ name: displayName,+ isVisitor: true+ };++ _onSetMessageRecipient(visitorParticipant);+ } else {+ _onSetMessageRecipient(_participant);+ }- _onSetMessageRecipient(_participant);_onSendMessage(message);return true;@@ -88,7 +111,7 @@ export function _mapDispatchToProps(dispatch: IStore['dispatch']) {dispatch(sendMessage(message, true));},- _onSetMessageRecipient: (participant: IParticipant) => {+ _onSetMessageRecipient: (participant: IParticipant | IVisitorChatParticipant) => {dispatch(setPrivateMessageRecipient(participant));}};@@ -103,6 +126,6 @@ export function _mapDispatchToProps(dispatch: IStore['dispatch']) {*/export function _mapStateToProps(state: IReduxState, ownProps: IProps) {return {- _participant: getParticipantById(state, ownProps.participantID)+ _participant: ownProps.isFromVisitor ? undefined : getParticipantById(state, ownProps.participantID)};}diff --git a/react/features/chat/components/AbstractMessageRecipient.ts b/react/features/chat/components/AbstractMessageRecipient.tsindex caf01f6677..3797658958 100644--- a/react/features/chat/components/AbstractMessageRecipient.ts+++ b/react/features/chat/components/AbstractMessageRecipient.ts@@ -3,7 +3,9 @@ import { WithTranslation } from 'react-i18next';import { IReduxState, IStore } from '../../app/types';import { getParticipantDisplayName, isLocalParticipantModerator } from '../../base/participants/functions';+import { getVisitorDisplayName } from '../../visitors/functions';import { setLobbyChatActiveState, setPrivateMessageRecipient } from '../actions.any';+import { isVisitorChatParticipant } from '../functions';export interface IProps extends WithTranslation {@@ -13,6 +15,11 @@ export interface IProps extends WithTranslation {*/_isLobbyChatActive: boolean;+ /**+ * Whether the private message recipient is a visitor.+ */+ _isVisitor?: boolean;+/*** The name of the lobby message recipient, if any.*/@@ -72,10 +79,18 @@ export function _mapDispatchToProps(dispatch: IStore['dispatch']) {*/export function _mapStateToProps(state: IReduxState, _ownProps: any) {const { privateMessageRecipient, lobbyMessageRecipient, isLobbyChatActive } = state['features/chat'];+ let _privateMessageRecipient;+ const _isVisitor = isVisitorChatParticipant(privateMessageRecipient);++ if (privateMessageRecipient) {+ _privateMessageRecipient = _isVisitor+ ? getVisitorDisplayName(state, privateMessageRecipient.name)+ : getParticipantDisplayName(state, privateMessageRecipient.id);+ }return {- _privateMessageRecipient:- privateMessageRecipient ? getParticipantDisplayName(state, privateMessageRecipient.id) : undefined,+ _privateMessageRecipient,+ _isVisitor,_isLobbyChatActive: isLobbyChatActive,_lobbyMessageRecipient:isLobbyChatActive && lobbyMessageRecipient ? lobbyMessageRecipient.name : undefined,diff --git a/react/features/chat/components/native/ChatMessage.tsx b/react/features/chat/components/native/ChatMessage.tsxindex de52807d11..adacd5fbc0 100644--- a/react/features/chat/components/native/ChatMessage.tsx+++ b/react/features/chat/components/native/ChatMessage.tsx@@ -122,15 +122,17 @@ class ChatMessage extends Component<IChatMessageProps> {* @returns {React.ReactElement<*> | null}*/_renderDisplayName() {- const { message, showDisplayName } = this.props;+ const { message, showDisplayName, t } = this.props;if (!showDisplayName) {return null;}+ const { displayName, isFromVisitor } = message;+return (<Text style = { styles.senderDisplayName }>- { message.displayName }+ { `${displayName}${isFromVisitor ? ` ${t('visitors.chatIndicator')}` : ''}` }</Text>);}diff --git a/react/features/chat/components/native/MessageRecipient.tsx b/react/features/chat/components/native/MessageRecipient.tsxindex 6319749a5b..660a6b3c06 100644--- a/react/features/chat/components/native/MessageRecipient.tsx+++ b/react/features/chat/components/native/MessageRecipient.tsx@@ -12,7 +12,8 @@ import {} from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';import { setLobbyChatActiveState, setPrivateMessageRecipient } from '../../actions.any';import AbstractMessageRecipient, {- IProps as AbstractProps+ IProps as AbstractProps,+ _mapStateToProps as _mapStateToPropsAbstract} from '../AbstractMessageRecipient';import styles from './styles';@@ -36,11 +37,6 @@ interface IProps extends AbstractProps {id: string;name: string;} | ILocalParticipant;-- /**- * The participant object set for private messaging.- */- privateMessageRecipient: { name: string; };}/**@@ -96,7 +92,8 @@ class MessageRecipient extends AbstractMessageRecipient<IProps> {const {isLobbyChatActive,lobbyMessageRecipient,- privateMessageRecipient,+ _privateMessageRecipient,+ _isVisitor,t} = this.props;@@ -120,7 +117,7 @@ class MessageRecipient extends AbstractMessageRecipient<IProps> {);}- if (!privateMessageRecipient) {+ if (!_privateMessageRecipient) {return null;}@@ -130,7 +127,7 @@ class MessageRecipient extends AbstractMessageRecipient<IProps> {style = { styles.messageRecipientContainer as ViewStyle }><Text style = { styles.messageRecipientText }>{ t('chat.messageTo', {- recipient: privateMessageRecipient.name+ recipient: `${_privateMessageRecipient}${_isVisitor ? ` ${t('visitors.chatIndicator')}` : ''}`}) }</Text><TouchableHighlight@@ -157,6 +154,7 @@ function _mapStateToProps(state: IReduxState, _ownProps: any) {const { lobbyMessageRecipient, isLobbyChatActive } = state['features/chat'];return {+ ..._mapStateToPropsAbstract(state, _ownProps),isLobbyChatActive,lobbyMessageRecipient};diff --git a/react/features/chat/components/web/ChatMessage.tsx b/react/features/chat/components/web/ChatMessage.tsxindex 0bd7417153..743867f64a 100644--- a/react/features/chat/components/web/ChatMessage.tsx+++ b/react/features/chat/components/web/ChatMessage.tsx@@ -224,11 +224,13 @@ const ChatMessage = ({* @returns {React$Element<*>}*/function _renderDisplayName() {+ const { displayName, isFromVisitor = false } = message;+return (<divaria-hidden = { true }className = { cx('display-name', classes.displayName) }>- {message.displayName}+ {`${displayName}${isFromVisitor ? ` ${t('visitors.chatIndicator')}` : ''}`}</div>);}@@ -338,6 +340,8 @@ const ChatMessage = ({{!shouldDisplayChatMessageMenu && (<div className = { classes.optionsButtonContainer }>{isHovered && <MessageMenu+ displayName = { message.displayName }+ isFromVisitor = { message.isFromVisitor }isLobbyMessage = { message.lobbyChat }message = { message.message }participantId = { message.participantId }@@ -391,6 +395,8 @@ const ChatMessage = ({<div><div className = { classes.optionsButtonContainer }>{isHovered && <MessageMenu+ displayName = { message.displayName }+ isFromVisitor = { message.isFromVisitor }isLobbyMessage = { message.lobbyChat }message = { message.message }participantId = { message.participantId }@@ -414,7 +420,15 @@ function _mapStateToProps(state: IReduxState, { message }: IProps) {const { knocking } = state['features/lobby'];const participant = getParticipantById(state, message.participantId);- const enablePrivateChat = isPrivateChatEnabled(participant, state);++ // For visitor private messages, participant will be undefined but we should still allow private chat+ // Create a visitor participant object for visitor messages to pass to isPrivateChatEnabled+ const participantForCheck = message.isFromVisitor+ ? { id: message.participantId, name: message.displayName, isVisitor: true as const }+ : participant;++ const enablePrivateChat = (!message.isFromVisitor || message.privateMessage)+ && isPrivateChatEnabled(participantForCheck, state);return {shouldDisplayChatMessageMenu: enablePrivateChat,diff --git a/react/features/chat/components/web/MessageMenu.tsx b/react/features/chat/components/web/MessageMenu.tsxindex 1acfdde1f6..11e9cae322 100644--- a/react/features/chat/components/web/MessageMenu.tsx+++ b/react/features/chat/components/web/MessageMenu.tsx@@ -15,6 +15,8 @@ import { handleLobbyChatInitialized, openChat } from '../../actions.web';export interface IProps {className?: string;+ displayName?: string;+ isFromVisitor?: boolean;isLobbyMessage: boolean;message: string;participantId: string;@@ -58,7 +60,7 @@ const useStyles = makeStyles()(theme => {};});-const MessageMenu = ({ message, participantId, isLobbyMessage, shouldDisplayChatMessageMenu }: IProps) => {+const MessageMenu = ({ message, participantId, isFromVisitor, isLobbyMessage, shouldDisplayChatMessageMenu, displayName }: IProps) => {const dispatch = useDispatch();const { classes, cx } = useStyles();const { t } = useTranslation();@@ -82,10 +84,23 @@ const MessageMenu = ({ message, participantId, isLobbyMessage, shouldDisplayChatif (isLobbyMessage) {dispatch(handleLobbyChatInitialized(participantId));} else {- dispatch(openChat(participant));+ // For visitor messages, participant will be undefined but we can still open chat+ // using the participantId which contains the visitor's original JID+ if (isFromVisitor) {+ // Handle visitor participant that doesn't exist in main participant list+ const visitorParticipant = {+ id: participantId,+ name: displayName,+ isVisitor: true+ };++ dispatch(openChat(visitorParticipant));+ } else {+ dispatch(openChat(participant));+ }}handleClose();- }, [ dispatch, isLobbyMessage, participant, participantId ]);+ }, [ dispatch, isLobbyMessage, participant, participantId, displayName ]);const handleCopyClick = useCallback(() => {copyText(message)diff --git a/react/features/chat/components/web/MessageRecipient.tsx b/react/features/chat/components/web/MessageRecipient.tsxindex 21d6ed046c..51b7db880f 100644--- a/react/features/chat/components/web/MessageRecipient.tsx+++ b/react/features/chat/components/web/MessageRecipient.tsx@@ -48,6 +48,7 @@ const useStyles = makeStyles()(theme => {const MessageRecipient = ({_privateMessageRecipient,_isLobbyChatActive,+ _isVisitor,_lobbyMessageRecipient,_onRemovePrivateMessageRecipient,_onHideLobbyChatRecipient,@@ -80,9 +81,9 @@ const MessageRecipient = ({id = 'chat-recipient'role = 'alert'><span className = { classes.text }>- {t(_isLobbyChatActive ? 'chat.lobbyChatMessageTo' : 'chat.messageTo', {- recipient: _isLobbyChatActive ? _lobbyMessageRecipient : _privateMessageRecipient- })}+ { _isLobbyChatActive+ ? t('chat.lobbyChatMessageTo', { recipient: _lobbyMessageRecipient })+ : t('chat.messageTo', { recipient: `${_privateMessageRecipient}${_isVisitor ? ` ${t('visitors.chatIndicator')}` : ''}` }) }</span><ButtonaccessibilityLabel = { t('dialog.close') }diff --git a/react/features/chat/functions.ts b/react/features/chat/functions.tsindex 1d518b3fcf..1d6432cac2 100644--- a/react/features/chat/functions.ts+++ b/react/features/chat/functions.ts@@ -9,10 +9,12 @@ import { getLocalizedDateFormatter } from '../base/i18n/dateUtil';import i18next from '../base/i18n/i18next';import { MEET_FEATURES } from '../base/jwt/constants';import { isJwtFeatureEnabled } from '../base/jwt/functions';-import { getParticipantById } from '../base/participants/functions';+import { getParticipantById, isPrivateChatEnabled } from '../base/participants/functions';+import { IParticipant } from '../base/participants/types';import { escapeRegexp } from '../base/util/helpers';import { getParticipantsPaneWidth } from '../participants-pane/functions';import { VIDEO_SPACE_MIN_SIZE } from '../video-layout/constants';+import { IVisitorChatParticipant } from '../visitors/types';import { MESSAGE_TYPE_ERROR, MESSAGE_TYPE_LOCAL, TIMESTAMP_FORMAT } from './constants';import { IMessage } from './types';@@ -178,9 +180,24 @@ export function getCanReplyToMessage(state: IReduxState, message: IMessage) {const { knocking } = state['features/lobby'];const participant = getParticipantById(state, message.participantId);- return Boolean(participant)+ // Check if basic reply conditions are met+ const basicCanReply = (Boolean(participant) || message.isFromVisitor)&& (message.privateMessage || (message.lobbyChat && !knocking))&& message.messageType !== MESSAGE_TYPE_LOCAL;++ if (!basicCanReply) {+ return false;+ }++ // Check private chat configuration for visitor messages+ if (message.isFromVisitor) {+ const visitorParticipant = { id: message.participantId, name: message.displayName, isVisitor: true as const };++ return isPrivateChatEnabled(visitorParticipant, state);+ }++ // For non-visitor messages, use the regular participant+ return isPrivateChatEnabled(participant, state);}/**@@ -190,8 +207,19 @@ export function getCanReplyToMessage(state: IReduxState, message: IMessage) {* @returns {string}*/export function getPrivateNoticeMessage(message: IMessage) {+ let recipient;++ if (message.messageType === MESSAGE_TYPE_LOCAL) {+ // For messages sent by local user, show the recipient name+ // For visitor messages, use the visitor's display name with indicator+ recipient = message.sentToVisitor ? `${message.recipient} ${i18next.t('visitors.chatIndicator')}` : message.recipient;+ } else {+ // For messages received from others, show "you"+ recipient = i18next.t('chat.you');+ }+return i18next.t('chat.privateNotice', {- recipient: message.messageType === MESSAGE_TYPE_LOCAL ? message.recipient : i18next.t('chat.you')+ recipient});}@@ -225,3 +253,15 @@ export function getChatMaxSize(state: IReduxState) {return Math.max(clientWidth - getParticipantsPaneWidth(state) - VIDEO_SPACE_MIN_SIZE, 0);}++/**+ * Type guard to check if a participant is a visitor chat participant.+ *+ * @param {IParticipant | IVisitorChatParticipant | undefined} participant - The participant to check.+ * @returns {boolean} - True if the participant is a visitor chat participant.+ */+export function isVisitorChatParticipant(+ participant?: IParticipant | IVisitorChatParticipant+): participant is IVisitorChatParticipant {+ return Boolean(participant && 'isVisitor' in participant && participant.isVisitor === true);+}diff --git a/react/features/chat/middleware.ts b/react/features/chat/middleware.tsindex b2323321b8..0b4abf6e75 100644--- a/react/features/chat/middleware.ts+++ b/react/features/chat/middleware.ts@@ -33,8 +33,7 @@ import { pushReactions } from '../reactions/actions.any';import { ENDPOINT_REACTION_NAME } from '../reactions/constants';import { getReactionMessageFromBuffer, isReactionsEnabled } from '../reactions/functions.any';import { showToolbox } from '../toolbox/actions';--import './subscriber';+import { getVisitorDisplayName } from '../visitors/functions';import {ADD_MESSAGE,@@ -55,8 +54,9 @@ import {MESSAGE_TYPE_REMOTE,MESSAGE_TYPE_SYSTEM} from './constants';-import { getUnreadCount, isSendGroupChatDisabled } from './functions';+import { getUnreadCount, isSendGroupChatDisabled, isVisitorChatParticipant } from './functions';import { INCOMING_MSG_SOUND_FILE } from './sounds';+import './subscriber';/*** Timeout for when to show the privacy notice after a private message was received.@@ -186,6 +186,9 @@ MiddlewareRegistry.register(store => next => action => {if (participant) {action.participant = participant;+ } else if (isVisitorChatParticipant(privateMessageRecipient)) {+ // Handle visitor participants that don't exist in the main participant list+ action.participant = privateMessageRecipient;}}} else if (focusedTab === ChatTabs.POLLS) {@@ -204,14 +207,17 @@ MiddlewareRegistry.register(store => next => action => {// recipient. This logic tries to mitigate this risk.const shouldSendPrivateMessageTo = _shouldSendPrivateMessageTo(state, action);- const participantExists = shouldSendPrivateMessageTo- && getParticipantById(state, shouldSendPrivateMessageTo);+ if (shouldSendPrivateMessageTo) {+ const participantExists = getParticipantById(state, shouldSendPrivateMessageTo.id);- if (shouldSendPrivateMessageTo && participantExists) {- dispatch(openDialog(ChatPrivacyDialog, {- message: action.message,- participantID: shouldSendPrivateMessageTo- }));+ if (participantExists || shouldSendPrivateMessageTo.isFromVisitor) {+ dispatch(openDialog(ChatPrivacyDialog, {+ message: action.message,+ participantID: shouldSendPrivateMessageTo.id,+ isFromVisitor: shouldSendPrivateMessageTo.isFromVisitor,+ displayName: shouldSendPrivateMessageTo.name+ }));+ }} else {// Sending the message if privacy notice doesn't need to be shown.@@ -227,10 +233,10 @@ MiddlewareRegistry.register(store => next => action => {type: LOBBY_CHAT_MESSAGE,message: action.message}, lobbyMessageRecipient.id);- _persistSentPrivateMessage(store, lobbyMessageRecipient.id, action.message, true);+ _persistSentPrivateMessage(store, lobbyMessageRecipient, action.message, true);} else if (privateMessageRecipient) {- conference.sendPrivateTextMessage(privateMessageRecipient.id, action.message);- _persistSentPrivateMessage(store, privateMessageRecipient.id, action.message);+ conference.sendPrivateTextMessage(privateMessageRecipient.id, action.message, 'body', isVisitorChatParticipant(privateMessageRecipient));+ _persistSentPrivateMessage(store, privateMessageRecipient, action.message);} else {conference.sendTextMessage(action.message);}@@ -317,7 +323,7 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {JitsiConferenceEvents.MESSAGE_RECEIVED,/* eslint-disable max-params */(participantId: string, message: string, timestamp: number,- displayName: string, isGuest: boolean, messageId: string) => {+ displayName: string, isFromVisitor: boolean, messageId: string) => {/* eslint-enable max-params */_onConferenceMessageReceived(store, {// in case of messages coming from visitors we can have unknown id@@ -325,7 +331,7 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {message,timestamp,displayName,- isGuest,+ isFromVisitor,messageId,privateMessage: false });@@ -350,13 +356,15 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {conference.on(JitsiConferenceEvents.PRIVATE_MESSAGE_RECEIVED,- (participantId: string, message: string, timestamp: number, messageId: string) => {+ (participantId: string, message: string, timestamp: number, messageId: string, displayName?: string, isFromVisitor?: boolean) => {_onConferenceMessageReceived(store, {participantId,message,timestamp,+ displayName,messageId,- privateMessage: true+ privateMessage: true,+ isFromVisitor});});@@ -375,8 +383,8 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {* @returns {void}*/function _onConferenceMessageReceived(store: IStore,- { displayName, isGuest, message, messageId, participantId, privateMessage, timestamp }: {- displayName?: string; isGuest?: boolean; message: string; messageId?: string;+ { displayName, isFromVisitor, message, messageId, participantId, privateMessage, timestamp }: {+ displayName?: string; isFromVisitor?: boolean; message: string; messageId?: string;participantId: string; privateMessage: boolean; timestamp: number; }) {@@ -390,7 +398,7 @@ function _onConferenceMessageReceived(store: IStore,}_handleReceivedMessage(store, {displayName,- isGuest,+ isFromVisitor,participantId,message,privateMessage,@@ -505,8 +513,8 @@ function getLobbyChatDisplayName(state: IReduxState, participantId: string) {* @returns {void}*/function _handleReceivedMessage({ dispatch, getState }: IStore,- { displayName, isGuest, lobbyChat, message, messageId, participantId, privateMessage, timestamp }: {- displayName?: string; isGuest?: boolean; lobbyChat: boolean; message: string;+ { displayName, isFromVisitor, lobbyChat, message, messageId, participantId, privateMessage, timestamp }: {+ displayName?: string; isFromVisitor?: boolean; lobbyChat: boolean; message: string;messageId?: string; participantId: string; privateMessage: boolean; timestamp: number; },shouldPlaySound = true,isReaction = false@@ -525,9 +533,17 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,const participant = getParticipantById(state, participantId) || { local: undefined };const localParticipant = getLocalParticipant(getState);- let displayNameToShow = lobbyChat- ? getLobbyChatDisplayName(state, participantId)- : displayName || getParticipantDisplayName(state, participantId);+ let _displayName, displayNameToShow;++ if (lobbyChat) {+ displayNameToShow = _displayName = getLobbyChatDisplayName(state, participantId);+ } else if (isFromVisitor) {+ _displayName = getVisitorDisplayName(state, displayName);+ displayNameToShow = `${_displayName} ${i18next.t('visitors.chatIndicator')}`;+ } else {+ displayNameToShow = _displayName = getParticipantDisplayName(state, participantId);+ }+const hasRead = participant.local || isChatOpen;const timestampToDate = timestamp ? new Date(timestamp) : new Date();const millisecondsTimestamp = timestampToDate.getTime();@@ -536,12 +552,8 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,const shouldShowNotification = userSelectedNotifications?.['notify.chatMessages']&& !hasRead && !isReaction && (!timestamp || lobbyChat);- if (isGuest) {- displayNameToShow = `${displayNameToShow} ${i18next.t('visitors.chatIndicator')}`;- }-dispatch(addMessage({- displayName: displayNameToShow,+ displayName: _displayName,hasRead,participantId,messageType: participant.local ? MESSAGE_TYPE_LOCAL : MESSAGE_TYPE_REMOTE,@@ -551,7 +563,8 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,recipient: getParticipantDisplayName(state, localParticipant?.id ?? ''),timestamp: millisecondsTimestamp,messageId,- isReaction+ isReaction,+ isFromVisitor}));if (shouldShowNotification) {@@ -574,6 +587,15 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,}}+/**+ * Interface for recipient objects used in private messaging.+ */+interface IRecipient {+ id: string;+ isVisitor?: boolean;+ name?: string;+}+/*** Persists the sent private messages as if they were received over the muc.*@@ -582,12 +604,12 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,* But those messages should be in the store as well, otherwise they don't appear in the chat window.** @param {Store} store - The Redux store.- * @param {string} recipientID - The ID of the recipient the private message was sent to.+ * @param {IRecipient} recipient - The recipient the private message was sent to.* @param {string} message - The sent message.* @param {boolean} isLobbyPrivateMessage - Is a lobby message.* @returns {void}*/-function _persistSentPrivateMessage({ dispatch, getState }: IStore, recipientID: string,+function _persistSentPrivateMessage({ dispatch, getState }: IStore, recipient: IRecipient,message: string, isLobbyPrivateMessage = false) {const state = getState();const localParticipant = getLocalParticipant(state);@@ -598,6 +620,13 @@ function _persistSentPrivateMessage({ dispatch, getState }: IStore, recipientID:const displayName = getParticipantDisplayName(state, localParticipant.id);const { lobbyMessageRecipient } = state['features/chat'];+ const recipientName+ = recipient.isVisitor+ ? getVisitorDisplayName(state, recipient.name)+ : (isLobbyPrivateMessage+ ? lobbyMessageRecipient?.name+ : getParticipantDisplayName(getState, recipient?.id));+dispatch(addMessage({displayName,hasRead: true,@@ -606,20 +635,19 @@ function _persistSentPrivateMessage({ dispatch, getState }: IStore, recipientID:message,privateMessage: !isLobbyPrivateMessage,lobbyChat: isLobbyPrivateMessage,- recipient: isLobbyPrivateMessage- ? lobbyMessageRecipient?.name- : getParticipantDisplayName(getState, recipientID),+ recipient: recipientName,+ sentToVisitor: recipient.isVisitor,timestamp: Date.now()}));}/**- * Returns the ID of the participant who we may have wanted to send the message+ * Returns the participant info for who we may have wanted to send the message* that we're about to send.** @param {Object} state - The Redux state.* @param {Object} action - The action being dispatched now.- * @returns {string?}+ * @returns {IRecipient?} - The recipient info or undefined if no notice should be shown.*/function _shouldSendPrivateMessageTo(state: IReduxState, action: AnyAction) {if (action.ignorePrivacy) {@@ -651,7 +679,11 @@ function _shouldSendPrivateMessageTo(state: IReduxState, action: AnyAction) {if (lastMessage.privateMessage) {// We show the notice if the last received message was private.- return lastMessage.participantId;+ return {+ id: lastMessage.participantId,+ isFromVisitor: Boolean(lastMessage.isFromVisitor),+ name: lastMessage.displayName+ };}// But messages may come rapidly, we want to protect our users from mis-sending a message@@ -666,7 +698,11 @@ function _shouldSendPrivateMessageTo(state: IReduxState, action: AnyAction) {? recentPrivateMessages[0] : recentPrivateMessages[recentPrivateMessages.length - 1];if (recentPrivateMessage) {- return recentPrivateMessage.participantId;+ return {+ id: recentPrivateMessage.participantId,+ isFromVisitor: Boolean(recentPrivateMessage.isFromVisitor),+ name: recentPrivateMessage.displayName+ };}return undefined;diff --git a/react/features/chat/reducer.ts b/react/features/chat/reducer.tsindex 79eab4ea2d..791f5905ae 100644--- a/react/features/chat/reducer.ts+++ b/react/features/chat/reducer.ts@@ -1,6 +1,7 @@import { UPDATE_CONFERENCE_METADATA } from '../base/conference/actionTypes';import { ILocalParticipant, IParticipant } from '../base/participants/types';import ReducerRegistry from '../base/redux/ReducerRegistry';+import { IVisitorChatParticipant } from '../visitors/types';import {ADD_MESSAGE,@@ -51,7 +52,7 @@ export interface IChatState {} | ILocalParticipant;messages: IMessage[];nbUnreadMessages: number;- privateMessageRecipient?: IParticipant;+ privateMessageRecipient?: IParticipant | IVisitorChatParticipant;width: {current: number;userSet: number | null;@@ -64,6 +65,7 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, acconst newMessage: IMessage = {displayName: action.displayName,error: action.error,+ isFromVisitor: Boolean(action.isFromVisitor),participantId: action.participantId,isReaction: action.isReaction,messageId: action.messageId,@@ -73,6 +75,7 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, acprivateMessage: action.privateMessage,lobbyChat: action.lobbyChat,recipient: action.recipient,+ sentToVisitor: Boolean(action.sentToVisitor),timestamp: action.timestamp};diff --git a/react/features/chat/types.ts b/react/features/chat/types.tsindex c410d6a798..33b9c4892f 100644--- a/react/features/chat/types.ts+++ b/react/features/chat/types.ts@@ -5,6 +5,7 @@ import { IStore } from '../app/types';export interface IMessage {displayName: string;error?: Object;+ isFromVisitor?: boolean;isReaction: boolean;lobbyChat: boolean;message: string;@@ -14,6 +15,7 @@ export interface IMessage {privateMessage: boolean;reactions: Map<string, Set<string>>;recipient: string;+ sentToVisitor?: boolean;timestamp: number;}diff --git a/react/features/visitors/functions.ts b/react/features/visitors/functions.tsindex f40a82ac37..c62293c4d6 100644--- a/react/features/visitors/functions.ts+++ b/react/features/visitors/functions.ts@@ -139,3 +139,21 @@ export function shouldDisplayCurrentVisitorsList(stateful: IStateful): boolean {return isVisitorsListEnabled(state) && getVisitorsCount(state) > 0;}++/**+ *+ * @param state+ * @param displayName+ * @returns+ */+/**+ * Returns visitor's display name, falling back to the default remote display name+ * from config, or 'Fellow Jitster' if neither is available.+ *+ * @param {IReduxState} state - The Redux state.+ * @param {string} [displayName] - Optional display name to use if available.+ * @returns {string} - The display name for a visitor.+ */+export function getVisitorDisplayName(state: IReduxState, displayName?: string): string {+ return displayName || state['features/base/config'].defaultRemoteDisplayName || 'Fellow Jitster';+}diff --git a/react/features/visitors/reducer.ts b/react/features/visitors/reducer.tsindex a1f40ff182..b65e4b6aec 100644--- a/react/features/visitors/reducer.ts+++ b/react/features/visitors/reducer.ts@@ -12,7 +12,7 @@ import {UPDATE_VISITORS_LIST,VISITOR_PROMOTION_REQUEST} from './actionTypes';-import { IPromotionRequest, IVisitor } from './types';+import { IPromotionRequest, IVisitorListParticipant } from './types';const DEFAULT_STATE = {count: 0,@@ -22,7 +22,7 @@ const DEFAULT_STATE = {showNotification: false,supported: false,promotionRequests: [],- visitors: [] as IVisitor[],+ visitors: [] as IVisitorListParticipant[],visitorsListSubscribed: false};@@ -34,7 +34,7 @@ export interface IVisitorsState {inQueueCount?: number;promotionRequests: IPromotionRequest[];supported: boolean;- visitors: IVisitor[];+ visitors: IVisitorListParticipant[];visitorsListSubscribed: boolean;}ReducerRegistry.register<IVisitorsState>('features/visitors', (state = DEFAULT_STATE, action): IVisitorsState => {diff --git a/react/features/visitors/types.ts b/react/features/visitors/types.tsindex dff15db2af..4d332692bc 100644--- a/react/features/visitors/types.ts+++ b/react/features/visitors/types.ts@@ -3,7 +3,13 @@ export interface IPromotionRequest {nick: string;}-export interface IVisitor {+export interface IVisitorListParticipant {id: string;name: string;}++export interface IVisitorChatParticipant {+ id: string;+ isVisitor: true;+ name: string;+}diff --git a/resources/prosody-plugins/mod_fmuc.lua b/resources/prosody-plugins/mod_fmuc.luaindex d2c9228c6e..96264d2579 100644--- a/resources/prosody-plugins/mod_fmuc.lua+++ b/resources/prosody-plugins/mod_fmuc.lua@@ -530,12 +530,56 @@ module:hook('muc-occupant-groupchat', function(event)return true;end, 55); -- prosody check for visitor's chat is prio 50, we want to override it+-- Private messaging support for visitorsmodule:hook('muc-private-message', function(event)- -- private messaging is forbidden- event.origin.send(st.error_reply(event.stanza, 'auth', 'forbidden',- 'Private messaging is disabled on visitor nodes'));- return true;-end, 10);+ local room, stanza = event.room, event.stanza;+ local from = stanza.attr.from;+ local to = stanza.attr.to;+ local recipient_occupant = room:get_occupant_by_nick(to);+ local recipient_domain = recipient_occupant and jid.host(recipient_occupant.bare_jid) or nil;+ local sender_occupant = room:get_occupant_by_nick(from);+ local sender_domain = sender_occupant and jid.host(sender_occupant.bare_jid) or nil;++ if sender_domain == nil or recipient_domain == nil then+ return false;+ end++ -- If both sender and recipient are local (on this vnode)+ if sender_domain == local_domain and recipient_domain == local_domain then+ event.origin.send(st.error_reply(event.stanza, 'auth', 'forbidden',+ 'Private messaging between visitors is disabled on visitor nodes'));+ return false; -- Prevent sending the original message and stop further processing+ end++ -- If sender is local (visitor node) and recipient is from main prosody, forward to main prosody+ if sender_domain == local_domain and recipient_domain == main_domain then+ local original_to = stanza.attr.to;+ local original_from = stanza.attr.from;++ -- Add nick element for visitor identification+ -- remove existing nick to avoid forgery+ stanza:remove_children('nick', NICK_NS);+ local nick_element = sender_occupant:get_presence():get_child('nick', NICK_NS);+ if nick_element then+ stanza:add_child(nick_element);+ else+ stanza:tag('nick', { xmlns = NICK_NS }):text('anonymous'):up();+ end++ -- Forward to main prosody, preserving the resource and original from+ stanza.attr.to = jid.join(jid.node(room.jid), muc_domain_prefix..'.'..main_domain, jid.resource(to));+ module:send(stanza);+ return false; -- Prevent sending the original message and stop further processing+ end++ -- For main->visitor messages, let the default MUC handler process it+ -- We don't need to do anything special+ if sender_domain == main_domain and recipient_domain == local_domain then+ return; -- Return nothing, let other handlers continue. The default MUC handler will process it.+ end++ return false; -- Prevent sending the original message and stop further processing+end, 100); -- Lower priority to run after other handlers-- we calculate the stats on the configured interval (60 seconds by default)module:hook_global('stats-update', function ()diff --git a/resources/prosody-plugins/mod_visitors.lua b/resources/prosody-plugins/mod_visitors.luaindex ebeef30f2f..e0fc4e2a7d 100644--- a/resources/prosody-plugins/mod_visitors.lua+++ b/resources/prosody-plugins/mod_visitors.lua@@ -380,6 +380,73 @@ process_host_module(main_muc_component_config, function(host_module, host)return true;end, 55); -- prosody check for unknown participant chat is prio 50, we want to override it+ -- Handle private messages from visitor nodes to main participants+ -- This routes forwarded private messages through the proper MUC system+ host_module:hook('message/full', function(event)+ local stanza = event.stanza;++ -- Only handle chat messages (private messages)+ if stanza.attr.type ~= 'chat' then+ return; -- Let other handlers process non-chat messages+ end++ local to = stanza.attr.to;++ -- Early return if this is not targeted at our MUC component+ if jid.host(to) ~= main_muc_component_config then+ return; -- Not for our MUC component, let other handlers process+ end++ local from = stanza.attr.from;+ local from_host = jid.host(from);+ local to_node = jid.node(to);+ local to_resource = jid.resource(to);++ -- Check if this is a private message from a known visitor node+ local target_room_jid = jid.bare(to);++ -- Early return if we don't have any visitor nodes for this room+ if not (visitors_nodes[target_room_jid] and visitors_nodes[target_room_jid].nodes) then+ return; -- No visitor nodes for this room, let default MUC handle it+ end++ -- Early return if the from_host is not a known visitor node+ if not visitors_nodes[target_room_jid].nodes[from_host] then+ -- This could be a main->visitor message, let it go through s2s+ return; -- Not from a known visitor node, let default MUC handle it+ end++ -- At this point we know it's a visitor message, handle it+ local room = prosody.hosts[main_muc_component_config].modules.muc.get_room_from_jid(target_room_jid);+ if room then+ -- Find the occupant+ local occupant = room:get_occupant_by_nick(to);+ if occupant then+ -- Add addresses element (XEP-0033) to store original visitor JID for reply functionality+ stanza:tag('addresses', { xmlns = 'http://jabber.org/protocol/address' })+ :tag('address', { type = 'ofrom', jid = stanza.attr.from }):up()+ :up();++ -- Change from to be the main domain equivalent for proper client recognition+ -- Use bare JID without resource+ stanza.attr.from = jid.join(to_node, main_muc_component_config);++ room:route_to_occupant(occupant, stanza);++ return true;+ else+ module:log('warn', 'VISITOR PRIVATE MESSAGE: Occupant not found for %s', to);+ end+ else+ module:log('warn', 'VISITOR PRIVATE MESSAGE: Room not found for %s', to);+ end++ return false;+ end, 10); -- Normal priority since we're in the right place now++ -- Main->visitor private messages work via s2s routing automatically+ -- No special handling needed!+host_module:hook('muc-config-submitted/muc#roomconfig_roomsecret', function(event)if event.status_codes['104'] thenlocal room = event.room;