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(chat): add support for moderator message deletion (XEP-0425) (#17610)

Alok-work2364dd772263a3
diff --git a/lang/main.json b/lang/main.json
index fe9cfc4600..55f4c77a13 100644
--- a/lang/main.json
+++ b/lang/main.json
@@ -135,6 +135,8 @@
"messageAccessibleTitleMe": "me says:",
"messageTo": "Private message to {{recipient}}",
"messagebox": "Type a message",
+ "moderatedMessage": "Deleted by a moderator.",
+ "moderationReason": "Reason: {{reason}}",
"newMessages": "New messages",
"nickname": {
"featureChat": "chat",
diff --git a/react/features/base/conference/reducer.ts b/react/features/base/conference/reducer.ts
index 653e5071b5..392d3baec1 100644
--- a/react/features/base/conference/reducer.ts
+++ b/react/features/base/conference/reducer.ts
@@ -152,6 +152,7 @@ export interface IJitsiConference {
lobbyDenyAccess: Function;
lock: Function;
markParticipantVerified: Function;
+ moderateMessage: Function;
muteParticipant: Function;
myLobbyUserId: Function;
myUserId: Function;
diff --git a/react/features/chat/actionTypes.ts b/react/features/chat/actionTypes.ts
index 23e56b4517..35ffea11e4 100644
--- a/react/features/chat/actionTypes.ts
+++ b/react/features/chat/actionTypes.ts
@@ -62,6 +62,18 @@ export const CLOSE_CHAT = 'CLOSE_CHAT';
*/
export const EDIT_MESSAGE = 'EDIT_MESSAGE';
+/**
+ * The type of the action which signals to moderate a message
+ *
+ * {
+ * type: MODERATE_MESSAGE,
+ * messageId: string,
+ * moderatedBy: string,
+ * reason: string
+ * }
+ */
+export const MODERATE_MESSAGE = 'MODERATE_MESSAGE';
+
/**
* The type of the action which signals to display the chat panel.
*
@@ -84,6 +96,17 @@ export const OPEN_CHAT = 'OPEN_CHAT';
export const SEND_MESSAGE = 'SEND_MESSAGE';
/**
+ * The type of the action which signals to moderates a chat message.
+ *
+ * {
+ * type: SEND_MESSAGE_MODERATION,
+ * message: IMessage,
+ * reason: string
+ * }
+ */
+export const SEND_MESSAGE_MODERATION = 'SEND_MESSAGE_MODERATION';
+
+/*
* The type of the action which signals a request to retract
* (delete) a previously sent chat message.
*
diff --git a/react/features/chat/actions.any.ts b/react/features/chat/actions.any.ts
index 2dc01bd340..2f08c380a2 100644
--- a/react/features/chat/actions.any.ts
+++ b/react/features/chat/actions.any.ts
@@ -11,12 +11,14 @@ import {
CLEAR_CHAT_STATE,
CLOSE_CHAT,
EDIT_MESSAGE,
+ MODERATE_MESSAGE,
NOTIFY_PRIVATE_RECIPIENTS_CHANGED,
OPEN_CHAT,
REMOVE_LOBBY_CHAT_PARTICIPANT,
RETRACT_MESSAGE,
SEND_MESSAGE,
SEND_MESSAGE_EDIT,
+ SEND_MESSAGE_MODERATION,
SEND_MESSAGE_RETRACTION,
SEND_REACTION,
SET_CHAT_SEARCH_MATCH_INDEX,
@@ -484,3 +486,46 @@ export function handleLobbyChatInitialized(participantId: string) {
return conference?.sendLobbyMessage(payload);
};
}
+
+/**
+ * Requests moderation of a chat message.
+ *
+ * Dispatches the network action so other participants get notified, and
+ * optimistically marks the message as moderated in the local store too,
+ * since MESSAGE_MODERATED isn't guaranteed to be echoed back to the sender.
+ *
+ * @param {IMessage} message - The message to moderate.
+ * @param {string} reason - Reason to delete message.
+ * @returns {Function}
+ */
+export function sendMessageModeration(message: IMessage, reason?: string) {
+ return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
+ const state = getState();
+ const localParticipant = getLocalParticipant(state);
+
+ dispatch({
+ type: SEND_MESSAGE_MODERATION,
+ message,
+ reason
+ });
+
+ dispatch(moderateMessage(message.messageId, localParticipant?.id, reason));
+ };
+}
+
+/**
+ * Marks a message as moderated.
+ *
+ * @param {string} messageId - The moderated message id.
+ * @param {string} moderatorId - The participant id of the moderator.
+ * @param {string} reason - Optional moderation reason.
+ * @returns {Object}
+ */
+export function moderateMessage(messageId: string, moderatorId?: string, reason?: string) {
+ return {
+ type: MODERATE_MESSAGE,
+ messageId,
+ moderatorId,
+ reason
+ };
+}
diff --git a/react/features/chat/components/web/ChatMessage.tsx b/react/features/chat/components/web/ChatMessage.tsx
index e83095c53c..6273d53af9 100644
--- a/react/features/chat/components/web/ChatMessage.tsx
+++ b/react/features/chat/components/web/ChatMessage.tsx
@@ -453,6 +453,16 @@ const ChatMessage = ({
);
}, [ message?.reactions, isHovered, isReactionsOpen ]);
+ const messageText = message.isDeleted
+ ? (
+ message.messageType === MESSAGE_TYPE_LOCAL
+ ? t<string>('chat.deletedMessageByMe')
+ : t<string>('chat.deletedMessage')
+ )
+ : message.isModerated
+ ? t('chat.moderatedMessage')
+ : getMessageText(message);
+
const canEdit = message.messageType === MESSAGE_TYPE_LOCAL
&& !message.lobbyChat
&& !message.isReaction
@@ -469,14 +479,16 @@ const ChatMessage = ({
<div className = { classes.sideBySideContainer }>
{!shouldDisplayMenuOnRight && (
<div className = { classes.optionsButtonContainer }>
- {isHovered && <MessageMenu
+ {isHovered && !message.isModerated && <MessageMenu
canEdit = { canEdit }
displayName = { message.displayName }
enablePrivateChat = { Boolean(enablePrivateChat) }
isFileMessage = { isFileMessage(message) }
isFromVisitor = { message.isFromVisitor }
isLobbyMessage = { message.lobbyChat }
+ isModerated = { message.isModerated }
message = { message }
+ messageId = { message.messageId }
onEditMessage = { handleEditMessage }
participantId = { message.participantId } />}
</div>
@@ -495,8 +507,8 @@ const ChatMessage = ({
<div className = { classes.replyWrapper }>
<div className = { cx('messagecontent', classes.messageContent) }>
{showDisplayName && _renderDisplayName()}
- <div className = { cx('usermessage', classes.userMessage, message.isDeleted && classes.deletedMessage) }>
- {isFileMessage(message) ? (
+ <div className = { cx('usermessage', classes.userMessage, message.isDeleted && message.isModerated && classes.deletedMessage) }>
+ {!message.isModerated && isFileMessage(message) ? (
<FileMessage
message = { message }
screenReaderHelpText = { message.messageType === MESSAGE_TYPE_LOCAL
@@ -513,21 +525,21 @@ const ChatMessage = ({
: t<string>('chat.messageAccessibleTitle', {
user: message.displayName
}) }
- text = {
- message.isDeleted
- ? (
- message.messageType === MESSAGE_TYPE_LOCAL
- ? t<string>('chat.deletedMessageByMe')
- : t<string>('chat.deletedMessage')
- )
- : getMessageText(message)
- } />
+ text = { messageText } />
+ )}
+ {message.isModerated && message.moderationReason && (
+ <div className = { classes.privateMessageNotice } >
+ {t('chat.moderationReason', {
+ reason: message.moderationReason
+ })}
+ </div>
+
)}
{(message.privateMessage || (message.lobbyChat && !knocking))
&& _renderPrivateNotice()}
<div className = { classes.chatMessageFooter }>
<div className = { classes.chatMessageFooterLeft }>
- {!message.isDeleted && message.reactions && message.reactions.size > 0 && (
+ {!message.isDeleted && !message.isModerated && message.reactions && message.reactions.size > 0 && (
<>
{renderReactions}
</>
@@ -547,7 +559,7 @@ const ChatMessage = ({
{shouldDisplayMenuOnRight && (
<div className = { classes.sideBySideContainer }>
{!message.privateMessage && !message.lobbyChat
- && !message.isReaction && !message.isDeleted && <div>
+ && !message.isReaction && !message.isDeleted && !message.isModerated && <div>
<div className = { classes.optionsButtonContainer }>
{isHovered && <ReactButton
messageId = { message.messageId }
@@ -556,14 +568,16 @@ const ChatMessage = ({
</div>}
<div>
<div className = { classes.optionsButtonContainer }>
- {isHovered && !message.isDeleted && <MessageMenu
+ {isHovered && !message.isDeleted && !message.isModerated && <MessageMenu
canEdit = { canEdit }
displayName = { message.displayName }
enablePrivateChat = { Boolean(enablePrivateChat) }
isFileMessage = { isFileMessage(message) }
isFromVisitor = { message.isFromVisitor }
isLobbyMessage = { message.lobbyChat }
+ isModerated = { message.isModerated }
message = { message }
+ messageId = { message.messageId }
onEditMessage = { handleEditMessage }
participantId = { message.participantId } />}
</div>
diff --git a/react/features/chat/components/web/MessageMenu.tsx b/react/features/chat/components/web/MessageMenu.tsx
index 1a23fed315..20cc787c64 100644
--- a/react/features/chat/components/web/MessageMenu.tsx
+++ b/react/features/chat/components/web/MessageMenu.tsx
@@ -6,12 +6,12 @@ import { makeStyles } from 'tss-react/mui';
import { IReduxState } from '../../../app/types';
import { IconDotsHorizontal } from '../../../base/icons/svg';
-import { getParticipantById } from '../../../base/participants/functions';
+import { getParticipantById, isLocalParticipantModerator } from '../../../base/participants/functions';
import Popover from '../../../base/popover/components/Popover.web';
import Button from '../../../base/ui/components/web/Button';
import { BUTTON_TYPES } from '../../../base/ui/constants.any';
import { copyText } from '../../../base/util/copyText.web';
-import { sendMessageRetraction } from '../../actions.any';
+import { sendMessageModeration, sendMessageRetraction } from '../../actions.any';
import { handleLobbyChatInitialized, openChat } from '../../actions.web';
import { MESSAGE_TYPE_LOCAL } from '../../constants';
import logger from '../../logger';
@@ -25,7 +25,9 @@ export interface IProps {
isFileMessage?: boolean;
isFromVisitor?: boolean;
isLobbyMessage: boolean;
+ isModerated?: boolean;
message: IMessage;
+ messageId: string;
onEditMessage?: () => void;
participantId: string;
}
@@ -67,7 +69,7 @@ const useStyles = makeStyles()(theme => {
};
});
-const MessageMenu = ({ canEdit, message, isFromVisitor, isLobbyMessage, enablePrivateChat, displayName, isFileMessage, onEditMessage }: IProps) => {
+const MessageMenu = ({ canEdit, message, messageId, isFromVisitor, isLobbyMessage, isModerated, enablePrivateChat, displayName, isFileMessage, onEditMessage }: IProps) => {
const dispatch = useDispatch();
const { classes, cx } = useStyles();
const { t } = useTranslation();
@@ -77,6 +79,7 @@ const MessageMenu = ({ canEdit, message, isFromVisitor, isLobbyMessage, enablePr
left: 0 });
const buttonRef = useRef<HTMLDivElement>(null);
+ const isModerator = useSelector(isLocalParticipantModerator);
const participant = useSelector((state: IReduxState) => getParticipantById(state, message.participantId));
// If no menu items will be shown, don't render the menu button.
@@ -146,6 +149,11 @@ const MessageMenu = ({ canEdit, message, isFromVisitor, isLobbyMessage, enablePr
handleClose();
}, [ message, handleClose ]);
+ const handleModerateClick = useCallback(() => {
+ dispatch(sendMessageModeration({ messageId } as IMessage));
+ handleClose();
+ }, [ dispatch, messageId, handleClose ]);
+
const handleEditClick = useCallback(() => {
onEditMessage?.();
handleClose();
@@ -174,6 +182,13 @@ const MessageMenu = ({ canEdit, message, isFromVisitor, isLobbyMessage, enablePr
{t('Copy')}
</div>
)}
+ {isModerator && !isModerated && (
+ <div
+ className = { classes.menuItem }
+ onClick = { handleModerateClick }>
+ {t('chat.delete')}
+ </div>
+ )}
{message.messageType === MESSAGE_TYPE_LOCAL
&& !message.isDeleted
&& (
diff --git a/react/features/chat/constants.ts b/react/features/chat/constants.ts
index 459477f3be..62b70f26d6 100644
--- a/react/features/chat/constants.ts
+++ b/react/features/chat/constants.ts
@@ -75,6 +75,8 @@ export const MESSAGE_TYPE_SYSTEM = 'system_chat_message';
export const OPTION_GROUPCHAT = 'groupchat';
+export const MODERATE_CHAT_MESSAGE = 'MODERATE_CHAT_MESSAGE';
+
export const EDIT_CHAT_MESSAGE = 'editChat';
/**
diff --git a/react/features/chat/middleware.ts b/react/features/chat/middleware.ts
index 2b6dd76795..90423e36c4 100644
--- a/react/features/chat/middleware.ts
+++ b/react/features/chat/middleware.ts
@@ -47,6 +47,7 @@ import {
OPEN_CHAT,
SEND_MESSAGE,
SEND_MESSAGE_EDIT,
+ SEND_MESSAGE_MODERATION,
SEND_MESSAGE_RETRACTION,
SEND_REACTION,
SET_FOCUSED_TAB
@@ -57,6 +58,7 @@ import {
clearChatState,
closeChat,
editMessage,
+ moderateMessage,
notifyPrivateRecipientsChanged,
openChat,
retractMessage,
@@ -72,7 +74,8 @@ import {
MESSAGE_TYPE_ERROR,
MESSAGE_TYPE_LOCAL,
MESSAGE_TYPE_REMOTE,
- MESSAGE_TYPE_SYSTEM
+ MESSAGE_TYPE_SYSTEM,
+ MODERATE_CHAT_MESSAGE
} from './constants';
import {
getDisplayNameSuffix,
@@ -153,6 +156,10 @@ MiddlewareRegistry.register(store => next => action => {
const state = store.getState();
const { participant, data } = action;
+ if (data?.type === MODERATE_CHAT_MESSAGE) {
+ _onMessageModerated(store, data.messageId, data.moderatedBy, data.reason);
+ }
+
if (data?.type === EDIT_CHAT_MESSAGE && data.messageId && data.message) {
const trimmedMessage = String(data.message).slice(0, CHAR_LIMIT);
@@ -197,6 +204,11 @@ MiddlewareRegistry.register(store => next => action => {
case NON_PARTICIPANT_MESSAGE_RECEIVED: {
const { participantId, json: data } = action;
+ if (data?.type === MODERATE_CHAT_MESSAGE) {
+ _onMessageModerated(store, data.messageId, data.moderatedBy, data.reason);
+ break;
+ }
+
if (data?.type === MESSAGE_TYPE_SYSTEM && data.message) {
_handleReceivedMessage(store, {
displayName: data.displayName ?? i18next.t('chat.systemDisplayName'),
@@ -272,6 +284,11 @@ MiddlewareRegistry.register(store => next => action => {
const local = getLocalParticipant(state);
if (conference && action.participant?.id && local?.id) {
+ const moderatedMessages = state['features/chat'].messages.filter(
+ (m: IMessage) =>
+ m.isModerated
+ );
+
const editedMessages = state['features/chat'].messages.filter(
(m: IMessage) =>
m.isEdited
@@ -279,6 +296,31 @@ MiddlewareRegistry.register(store => next => action => {
&& m.messageType === MESSAGE_TYPE_LOCAL
);
+ if (moderatedMessages.length > 0) {
+ const sendWithRetry = (retries: number) => {
+ try {
+ moderatedMessages.forEach(message => {
+ conference.sendPrivateTextMessage(
+ action.participant.id,
+ JSON.stringify({
+ type: MODERATE_CHAT_MESSAGE,
+ messageId: message.messageId,
+ moderatedBy: message.moderatedBy,
+ reason: message.moderationReason
+ }),
+ 'json-message'
+ );
+ });
+ } catch (e) {
+ if (retries > 0) {
+ setTimeout(() => sendWithRetry(retries - 1), 1000);
+ }
+ }
+ };
+
+ setTimeout(() => sendWithRetry(3), 3000);
+ }
+
editedMessages.forEach(message => {
conference.sendPrivateTextMessage(
action.participant.id,
@@ -463,6 +505,20 @@ MiddlewareRegistry.register(store => next => action => {
break;
}
+ case SEND_MESSAGE_MODERATION: {
+ const state = store.getState();
+ const conference = getCurrentConference(state);
+
+ if (conference) {
+ conference.moderateMessage(
+ action.message.messageId,
+ action.reason
+ );
+ }
+
+ break;
+ }
+
case ADD_REACTION_MESSAGE: {
if (localParticipant?.id) {
_handleReceivedMessage(store, {
@@ -620,12 +676,17 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {
}
);
+ conference.on(
+ JitsiConferenceEvents.MESSAGE_MODERATED,
+ (messageId: string, moderatorId: string, reason?: string) => {
+ _onMessageModerated(store, messageId, moderatorId, reason);
+ });
+
conference.on(
JitsiConferenceEvents.MESSAGE_RETRACTED,
(participantId: string, messageId: string) => {
_onMessageRetracted(store, participantId, messageId);
- }
- );
+ });
conference.on(
JitsiConferenceEvents.CONFERENCE_ERROR, (errorType: string, error: Error) => {
@@ -690,6 +751,29 @@ function _onReactionReceived(store: IStore, { participantId, reactionList, messa
}
/**
+ * Handles a moderator message deletion.
+ *
+ * @param {Object} store - Redux store.
+ * @param {string} messageId - The id of the message which is being deleted.
+ * @param {string} moderatorId - The Id of the moderator.
+ * @param {string} reason - The reason for which message is deleted.
+ * @returns {void}
+ */
+function _onMessageModerated(store: IStore, messageId: string, moderatorId: string, reason?: string) {
+ const { messages } = store.getState()['features/chat'];
+
+ const originalMessage = messages.find(
+ message => message.messageId === messageId
+ );
+
+ if (!originalMessage) {
+ return;
+ }
+
+ store.dispatch(moderateMessage(messageId, moderatorId, reason));
+}
+
+/*
* Handles a retracted message.
*
* @param {Object} store - Redux store.
diff --git a/react/features/chat/reducer.ts b/react/features/chat/reducer.ts
index 8bdc690105..81b09c9f15 100644
--- a/react/features/chat/reducer.ts
+++ b/react/features/chat/reducer.ts
@@ -11,6 +11,7 @@ import {
CLEAR_CHAT_STATE,
CLOSE_CHAT,
EDIT_MESSAGE,
+ MODERATE_MESSAGE,
NOTIFY_PRIVATE_RECIPIENTS_CHANGED,
OPEN_CHAT,
REMOVE_LOBBY_CHAT_PARTICIPANT,
@@ -243,6 +244,26 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, ac
};
}
+ case MODERATE_MESSAGE: {
+ const messages = state.messages.map(message => {
+ if (message.messageId === action.messageId) {
+ return {
+ ...message,
+ isModerated: true,
+ moderatedBy: action.moderatorId,
+ moderationReason: action.reason
+ };
+ }
+
+ return message;
+ });
+
+ return {
+ ...state,
+ messages
+ };
+ }
+
case RETRACT_MESSAGE: {
const messages = state.messages.map(message => {
if (message.messageId === action.messageId && message.participantId === action.retractedBy) {
diff --git a/react/features/chat/types.ts b/react/features/chat/types.ts
index 80516e0902..7fa5b5a900 100644
--- a/react/features/chat/types.ts
+++ b/react/features/chat/types.ts
@@ -23,11 +23,14 @@ export interface IMessage {
isEdited?: Boolean;
isFromGuest?: boolean;
isFromVisitor?: boolean;
+ isModerated?: boolean;
isReaction: boolean;
lobbyChat: boolean;
message: string;
messageId: string;
messageType: ChatMessageType;
+ moderatedBy?: string;
+ moderationReason?: string;
participantId: string;
privateMessage: boolean;
reactions: Map<string, Set<string>>;