Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(display-name): Handles new display-name extension in messages.

damenchoc069c0d7c3db
diff --git a/lang/main.json b/lang/main.json
index 0e234378b7..de226ea662 100644
--- a/lang/main.json
+++ b/lang/main.json
@@ -114,6 +114,7 @@
"error": "Error: your message was not sent. Reason: {{error}}",
"everyone": "Everyone",
"fieldPlaceHolder": "Aa",
+ "guestsChatIndicator": "(guest)",
"lobbyChatMessageTo": "Lobby chat message to {{recipient}}",
"message": "Message",
"messageAccessibleTitle": "{{user}} says:",
diff --git a/react/features/calendar-sync/web/microsoftCalendar.ts b/react/features/calendar-sync/web/microsoftCalendar.ts
index 7633e50e8a..26e2b41a35 100644
--- a/react/features/calendar-sync/web/microsoftCalendar.ts
+++ b/react/features/calendar-sync/web/microsoftCalendar.ts
@@ -170,7 +170,7 @@ export const microsoftCalendarApi = {
popupAuthWindow = window.open(
authUrl,
- 'Auth M$',
+ `Auth M$-${Date.now()}`,
`width=${w}, height=${h}, top=${
(screen.height / 2) - (h / 2)}, left=${
(screen.width / 2) - (w / 2)}`);
diff --git a/react/features/chat/components/AbstractMessageRecipient.ts b/react/features/chat/components/AbstractMessageRecipient.ts
index 3797658958..6dc85c4688 100644
--- a/react/features/chat/components/AbstractMessageRecipient.ts
+++ b/react/features/chat/components/AbstractMessageRecipient.ts
@@ -3,7 +3,7 @@ import { WithTranslation } from 'react-i18next';
import { IReduxState, IStore } from '../../app/types';
import { getParticipantDisplayName, isLocalParticipantModerator } from '../../base/participants/functions';
-import { getVisitorDisplayName } from '../../visitors/functions';
+import { getDisplayName } from '../../visitors/functions';
import { setLobbyChatActiveState, setPrivateMessageRecipient } from '../actions.any';
import { isVisitorChatParticipant } from '../functions';
@@ -84,7 +84,7 @@ export function _mapStateToProps(state: IReduxState, _ownProps: any) {
if (privateMessageRecipient) {
_privateMessageRecipient = _isVisitor
- ? getVisitorDisplayName(state, privateMessageRecipient.name)
+ ? getDisplayName(state, privateMessageRecipient.name)
: getParticipantDisplayName(state, privateMessageRecipient.id);
}
diff --git a/react/features/chat/components/native/ChatMessage.tsx b/react/features/chat/components/native/ChatMessage.tsx
index adacd5fbc0..c0addb1dc8 100644
--- a/react/features/chat/components/native/ChatMessage.tsx
+++ b/react/features/chat/components/native/ChatMessage.tsx
@@ -10,6 +10,7 @@ import { isGifEnabled, isGifMessage } from '../../../gifs/functions.native';
import { CHAR_LIMIT, MESSAGE_TYPE_ERROR, MESSAGE_TYPE_LOCAL } from '../../constants';
import {
getCanReplyToMessage,
+ getDisplayNameSuffix,
getFormattedTimestamp,
getMessageText,
getPrivateNoticeMessage,
@@ -122,17 +123,17 @@ class ChatMessage extends Component<IChatMessageProps> {
* @returns {React.ReactElement<*> | null}
*/
_renderDisplayName() {
- const { message, showDisplayName, t } = this.props;
+ const { message, showDisplayName } = this.props;
if (!showDisplayName) {
return null;
}
- const { displayName, isFromVisitor } = message;
+ const { displayName } = message;
return (
<Text style = { styles.senderDisplayName }>
- { `${displayName}${isFromVisitor ? ` ${t('visitors.chatIndicator')}` : ''}` }
+ { `${displayName}${getDisplayNameSuffix(message)}` }
</Text>
);
}
diff --git a/react/features/chat/components/web/ChatMessage.tsx b/react/features/chat/components/web/ChatMessage.tsx
index d332e12349..9bbfd4ea28 100644
--- a/react/features/chat/components/web/ChatMessage.tsx
+++ b/react/features/chat/components/web/ChatMessage.tsx
@@ -9,7 +9,7 @@ import { getParticipantById, getParticipantDisplayName, isPrivateChatEnabled } f
import Popover from '../../../base/popover/components/Popover.web';
import Message from '../../../base/react/components/web/Message';
import { MESSAGE_TYPE_LOCAL } from '../../constants';
-import { getFormattedTimestamp, getMessageText, getPrivateNoticeMessage } from '../../functions';
+import { getDisplayNameSuffix, getFormattedTimestamp, getMessageText, getPrivateNoticeMessage } from '../../functions';
import { IChatMessageProps } from '../../types';
import MessageMenu from './MessageMenu';
@@ -226,13 +226,13 @@ const ChatMessage = ({
* @returns {React$Element<*>}
*/
function _renderDisplayName() {
- const { displayName, isFromVisitor = false } = message;
+ const { displayName } = message;
return (
<div
aria-hidden = { true }
className = { cx('display-name', classes.displayName) }>
- {`${displayName}${isFromVisitor ? ` ${t('visitors.chatIndicator')}` : ''}`}
+ {`${displayName}${getDisplayNameSuffix(message)}`}
</div>
);
}
diff --git a/react/features/chat/functions.ts b/react/features/chat/functions.ts
index 1d6432cac2..c554b6d709 100644
--- a/react/features/chat/functions.ts
+++ b/react/features/chat/functions.ts
@@ -265,3 +265,21 @@ export function isVisitorChatParticipant(
): participant is IVisitorChatParticipant {
return Boolean(participant && 'isVisitor' in participant && participant.isVisitor === true);
}
+
+/**
+ * Returns a suffix to be appended to the display name based on the message origin.
+ *
+ * @param {IMessage} message - The message.
+ * @returns {string} The suffix, if any.
+ */
+export function getDisplayNameSuffix(message: IMessage): string {
+ let suffix = '';
+
+ if (message.isFromVisitor) {
+ suffix = ` ${i18next.t('visitors.chatIndicator')}`;
+ } else if (message.isFromGuest) {
+ suffix = ` ${i18next.t('chat.guestsChatIndicator')}`;
+ }
+
+ return suffix;
+}
diff --git a/react/features/chat/middleware.ts b/react/features/chat/middleware.ts
index 52583fd127..dfe26a553d 100644
--- a/react/features/chat/middleware.ts
+++ b/react/features/chat/middleware.ts
@@ -35,7 +35,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 { getVisitorDisplayName } from '../visitors/functions';
+import { getDisplayName } from '../visitors/functions';
import {
ADD_MESSAGE,
@@ -63,7 +63,12 @@ import {
MESSAGE_TYPE_REMOTE,
MESSAGE_TYPE_SYSTEM
} from './constants';
-import { getUnreadCount, isSendGroupChatDisabled, isVisitorChatParticipant } from './functions';
+import {
+ getDisplayNameSuffix,
+ getUnreadCount,
+ isSendGroupChatDisabled,
+ isVisitorChatParticipant
+} from './functions';
import { INCOMING_MSG_SOUND_FILE } from './sounds';
import './subscriber';
@@ -366,7 +371,7 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {
JitsiConferenceEvents.MESSAGE_RECEIVED,
/* eslint-disable max-params */
(participantId: string, message: string, timestamp: number,
- displayName: string, isFromVisitor: boolean, messageId: string) => {
+ displayName: string, isFromVisitor: boolean, messageId: string, source: string) => {
/* eslint-enable max-params */
_onConferenceMessageReceived(store, {
// in case of messages coming from visitors we can have unknown id
@@ -376,7 +381,9 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {
displayName,
isFromVisitor,
messageId,
- privateMessage: false });
+ source,
+ privateMessage: false
+ });
if (isSendGroupChatDisabled(store.getState()) && participantId) {
const participant = getParticipantById(store, participantId);
@@ -426,9 +433,9 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {
* @returns {void}
*/
function _onConferenceMessageReceived(store: IStore,
- { displayName, isFromVisitor, message, messageId, participantId, privateMessage, timestamp }: {
+ { displayName, isFromVisitor, message, messageId, participantId, privateMessage, timestamp, source }: {
displayName?: string; isFromVisitor?: boolean; message: string; messageId?: string;
- participantId: string; privateMessage: boolean; timestamp: number; }
+ participantId: string; privateMessage: boolean; source?: string; timestamp: number; }
) {
const isGif = isGifEnabled(store.getState()) && isGifMessage(message);
@@ -447,7 +454,8 @@ function _onConferenceMessageReceived(store: IStore,
privateMessage,
lobbyChat: false,
timestamp,
- messageId
+ messageId,
+ source
}, true, isGif);
}
@@ -556,9 +564,9 @@ function getLobbyChatDisplayName(state: IReduxState, participantId: string) {
* @returns {void}
*/
function _handleReceivedMessage({ dispatch, getState }: IStore,
- { displayName, isFromVisitor, lobbyChat, message, messageId, participantId, privateMessage, timestamp }: {
+ { displayName, isFromVisitor, lobbyChat, message, messageId, participantId, privateMessage, source, timestamp }: {
displayName?: string; isFromVisitor?: boolean; lobbyChat: boolean; message: string;
- messageId?: string; participantId: string; privateMessage: boolean; timestamp: number; },
+ messageId?: string; participantId: string; privateMessage: boolean; source?: string; timestamp: number; },
shouldPlaySound = true,
isReaction = false
) {
@@ -571,35 +579,33 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,
dispatch(playSound(INCOMING_MSG_SOUND_ID));
}
- // Provide a default for the case when a message is being
- // backfilled for a participant that has left the conference.
- const participant = getParticipantById(state, participantId) || { local: undefined };
+ const participant = getParticipantById(state, participantId);
const localParticipant = getLocalParticipant(getState);
- let _displayName, displayNameToShow;
+ let _displayName;
if (lobbyChat) {
- displayNameToShow = _displayName = getLobbyChatDisplayName(state, participantId);
+ _displayName = getLobbyChatDisplayName(state, participantId);
} else if (isFromVisitor) {
- _displayName = getVisitorDisplayName(state, displayName);
- displayNameToShow = `${_displayName} ${i18next.t('visitors.chatIndicator')}`;
+ _displayName = getDisplayName(state, displayName);
+ } else if (!participant) {
+ _displayName = getDisplayName(state, displayName);
} else {
- displayNameToShow = _displayName = getParticipantDisplayName(state, participantId);
+ _displayName = getParticipantDisplayName(state, participantId);
}
- const hasRead = participant.local || isChatOpen;
+ const hasRead = participant?.local || isChatOpen;
const timestampToDate = timestamp ? new Date(timestamp) : new Date();
const millisecondsTimestamp = timestampToDate.getTime();
// skip message notifications on join (the messages having timestamp - coming from the history)
const shouldShowNotification = userSelectedNotifications?.['notify.chatMessages']
&& !hasRead && !isReaction && (!timestamp || lobbyChat);
-
- dispatch(addMessage({
+ const newMessage = {
displayName: _displayName,
hasRead,
participantId,
- messageType: participant.local ? MESSAGE_TYPE_LOCAL : MESSAGE_TYPE_REMOTE,
+ messageType: participant?.local ? MESSAGE_TYPE_LOCAL : MESSAGE_TYPE_REMOTE,
message,
privateMessage,
lobbyChat,
@@ -607,12 +613,26 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,
timestamp: millisecondsTimestamp,
messageId,
isReaction,
- isFromVisitor
- }));
+ isFromVisitor,
+ isFromGuest: source === 'guest'
+ };
+
+ dispatch(addMessage(newMessage));
+
+ let notificationDisplayName = _displayName;
+
+ // source can be 'token' or 'guest'. When it is 'guest', we append a guest indicator
+ // to the display name to notify users that this message can be anything, while the token one is coming
+ // from a trusted source (the jwt token, the name can be locked from the backend if the
+ // token has the feature 'name-readonly')
+ if (isFromVisitor || (!participant && source === 'guest')) {
+ // @ts-ignore
+ notificationDisplayName = `${_displayName} ${getDisplayNameSuffix(newMessage)}`;
+ }
if (shouldShowNotification) {
dispatch(showMessageNotification({
- title: displayNameToShow,
+ title: notificationDisplayName,
description: message
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
}
@@ -623,7 +643,7 @@ function _handleReceivedMessage({ dispatch, getState }: IStore,
APP.API.notifyReceivedChatMessage({
body: message,
from: participantId,
- nick: displayNameToShow,
+ nick: notificationDisplayName,
privateMessage,
ts: timestamp
});
@@ -665,7 +685,7 @@ function _persistSentPrivateMessage({ dispatch, getState }: IStore, recipient: I
const recipientName
= recipient.isVisitor
- ? getVisitorDisplayName(state, recipient.name)
+ ? getDisplayName(state, recipient.name)
: (isLobbyPrivateMessage
? lobbyMessageRecipient?.name
: getParticipantDisplayName(getState, recipient?.id));
diff --git a/react/features/chat/reducer.ts b/react/features/chat/reducer.ts
index 197f30308d..c6e47960b7 100644
--- a/react/features/chat/reducer.ts
+++ b/react/features/chat/reducer.ts
@@ -68,6 +68,7 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, ac
const newMessage: IMessage = {
displayName: action.displayName,
error: action.error,
+ isFromGuest: Boolean(action.isFromGuest),
isFromVisitor: Boolean(action.isFromVisitor),
participantId: action.participantId,
isReaction: action.isReaction,
diff --git a/react/features/chat/types.ts b/react/features/chat/types.ts
index 340c7016a1..aaddc16e89 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;
+ isFromGuest?: boolean;
isFromVisitor?: boolean;
isReaction: boolean;
lobbyChat: boolean;
diff --git a/react/features/visitors/functions.ts b/react/features/visitors/functions.ts
index c62293c4d6..0369449d68 100644
--- a/react/features/visitors/functions.ts
+++ b/react/features/visitors/functions.ts
@@ -141,19 +141,13 @@ export function shouldDisplayCurrentVisitorsList(stateful: IStateful): boolean {
}
/**
- *
- * @param state
- * @param displayName
- * @returns
- */
-/**
- * Returns visitor's display name, falling back to the default remote display name
+ * Returns 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.
+ * @returns {string} - The display name.
*/
-export function getVisitorDisplayName(state: IReduxState, displayName?: string): string {
+export function getDisplayName(state: IReduxState, displayName?: string): string {
return displayName || state['features/base/config'].defaultRemoteDisplayName || 'Fellow Jitster';
}
diff --git a/resources/prosody-plugins/mod_fmuc.lua b/resources/prosody-plugins/mod_fmuc.lua
index 96264d2579..7eaa8b99e7 100644
--- a/resources/prosody-plugins/mod_fmuc.lua
+++ b/resources/prosody-plugins/mod_fmuc.lua
@@ -53,6 +53,7 @@ local muc_domain_prefix = module:get_option_string('muc_mapper_domain_prefix', '
local local_muc_domain = muc_domain_prefix..'.'..local_domain;
local NICK_NS = 'http://jabber.org/protocol/nick';
+local DISPLAY_NAME_NS = 'http://jitsi.org/protocol/display-name';
-- in certain cases we consider participants with token as moderators, this is the default behavior which can be turned off
local auto_promoted_with_token = module:get_option_boolean('visitors_auto_promoted_with_token', true);
@@ -480,6 +481,30 @@ process_host_module(local_domain, function(host_module, host)
host_module:hook('message/full', message_handler);
end);
+-- add to message stanza display name for the visitor
+-- remove existing nick to avoid forgery
+local function process_display_name(stanza, occupant)
+ -- TODO drop nick extension used in messages in favor of new display-name extension
+ -- we want mobile client to update before dropping support for nick from messages
+ stanza:remove_children('nick', NICK_NS);
+ stanza:remove_children('display-name', DISPLAY_NAME_NS);
+ local nick_element = occupant:get_presence():get_child('nick', NICK_NS);
+ if nick_element then
+ stanza:add_child(nick_element);
+ stanza:tag('display-name', {
+ xmlns = DISPLAY_NAME_NS,
+ source = 'visitor'
+ }):text(nick_element:get_text()):up();
+ else
+ stanza:tag('nick', { xmlns = NICK_NS })
+ :text('anonymous'):up();
+ stanza:tag('display-name', {
+ xmlns = DISPLAY_NAME_NS,
+ source = 'visitor'
+ }):text('anonymous'):up();
+ end
+end
+
-- only live chat is supported for visitors
module:hook('muc-occupant-groupchat', function(event)
local occupant, room, stanza = event.occupant, event.room, event.stanza;
@@ -492,16 +517,7 @@ module:hook('muc-occupant-groupchat', function(event)
-- we manage nick only for visitors
if occupant_host ~= main_domain then
- -- add to message stanza display name for the visitor
- -- remove existing nick to avoid forgery
- stanza:remove_children('nick', NICK_NS);
- local nick_element = 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
+ process_display_name(stanza, occupant);
end
stanza.attr.from = occupant.nick;
@@ -556,15 +572,7 @@ module:hook('muc-private-message', function(event)
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
+ process_display_name(stanza, sender_occupant);
-- 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));
diff --git a/resources/prosody-plugins/mod_muc_displayname.lua b/resources/prosody-plugins/mod_muc_displayname.lua
index 33d87a5bd1..a8276cff11 100644
--- a/resources/prosody-plugins/mod_muc_displayname.lua
+++ b/resources/prosody-plugins/mod_muc_displayname.lua
@@ -13,6 +13,11 @@ local is_admin = util.is_admin;
local ends_with = util.ends_with;
local internal_room_jid_match_rewrite = util.internal_room_jid_match_rewrite;
local NICK_NS = 'http://jabber.org/protocol/nick';
+local DISPLAY_NAME_NS = 'http://jitsi.org/protocol/display-name';
+
+local sessions = prosody.full_sessions;
+
+local ignore_jwt_name = module:get_option_boolean('ignore_jwt_name', false);
-- we need to get the shared resource for joining moderators, as participants are marked as moderators
-- after joining which is after the filter for stanza/out, but we need to know will this participant be a moderator
@@ -75,6 +80,56 @@ function filter_stanza_in(stanza, session)
return stanza;
end
+-- 'muc-add-history' is called in 'muc-broadcast-message' with priority 0
+-- we want to clean up message after we have processed it for history, but do it for all messages
+-- not only those that are added to history (as someone can forge a message and add 'no-store')
+module:hook('muc-broadcast-message', function(event)
+ -- any message that is about to be delivered, clear up nick and display-name elements
+ event.stanza:remove_children('nick', NICK_NS);
+ event.stanza:remove_children('display-name', DISPLAY_NAME_NS);
+end, -1);
+
+module:hook('muc-add-history', function(event)
+ local room, stanza = event.room, event.stanza;
+ local name;
+ local source;
+
+ local occupant = room:get_occupant_by_nick(stanza.attr.from);
+
+ if occupant then
+ local session = sessions[occupant.jid];
+ if session and session.jitsi_meet_context_user then
+ if ignore_jwt_name then
+ name = occupant:get_presence():get_child('nick', NICK_NS):get_text();
+ else
+ name = session.jitsi_meet_context_user.name;
+ end
+
+ source = 'token';
+ else
+ name = occupant:get_presence():get_child('nick', NICK_NS):get_text();
+ source = 'guest';
+ end
+ else
+ -- if no occupant found it is a message from visitor let's check display-name source
+ local display_name_element = stanza:get_child('display-name', DISPLAY_NAME_NS);
+ if display_name_element and display_name_element.attr.source == 'visitor' then
+ name = display_name_element:get_text();
+ source = display_name_element.attr.source;
+ end
+ end
+
+ if name then
+ -- clone the stanza, so only history has the display_name extension
+ event.stanza = st.clone(stanza);
+
+ event.stanza:tag('display-name', {
+ xmlns = DISPLAY_NAME_NS,
+ source = source
+ }):text(name):up();
+ end
+end);
+
function filter_session(session)
filters.add_filter(session, 'stanzas/out', filter_stanza_out, -100);
filters.add_filter(session, 'stanzas/in', filter_stanza_in, -100);