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): Adds an option to demote participants to visitors.
damenchof1d433266894
diff --git a/config.js b/config.jsindex aa81e8830e..e3e89a070e 100644--- a/config.js+++ b/config.js@@ -1300,6 +1300,8 @@ var config = {// remoteVideoMenu: {// // Whether the remote video context menu to be rendered or not.// disabled: true,+ // // If set to true the 'Switch to visitor' button will be disabled.+ // disableDemote: true,// // If set to true the 'Kick out' button will be disabled.// disableKick: true,// // If set to true the 'Grant moderator' button will be disabled.diff --git a/lang/main.json b/lang/main.jsonindex ad5e98fdd2..02a2ba36cd 100644--- a/lang/main.json+++ b/lang/main.json@@ -305,6 +305,8 @@"contactSupport": "Contact support","copied": "Copied","copy": "Copy",+ "demoteParticipantDialog": "Are you sure you want to move this participant to visitor?",+ "demoteParticipantTitle": "Move to visitor","dismiss": "Dismiss","displayNameRequired": "Hi! What’s your name?","done": "Done",@@ -1420,6 +1422,7 @@},"videothumbnail": {"connectionInfo": "Connection Info",+ "demote": "Move to visitor","domute": "Mute","domuteOthers": "Mute everyone else","domuteVideo": "Disable camera",@@ -1474,6 +1477,7 @@"chatIndicator": "(visitor)","labelTooltip": "Number of visitors: {{count}}","notification": {+ "demoteDescription": "Sent here by {{actor}}, raise your hand to participate","description": "To participate raise your hand","title": "You are a visitor in the meeting"}diff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.tsindex a42f6e6267..6ce48ef697 100644--- a/react/features/base/config/configType.ts+++ b/react/features/base/config/configType.ts@@ -500,6 +500,7 @@ export interface IConfig {suggestRecording?: boolean;};remoteVideoMenu?: {+ disableDemote?: boolean;disableGrantModerator?: boolean;disableKick?: boolean;disablePrivateChat?: boolean;diff --git a/react/features/base/connection/actionTypes.ts b/react/features/base/connection/actionTypes.tsindex 10ae0667da..5f9df75a0f 100644--- a/react/features/base/connection/actionTypes.ts+++ b/react/features/base/connection/actionTypes.ts@@ -52,6 +52,16 @@ export const CONNECTION_WILL_CONNECT = 'CONNECTION_WILL_CONNECT';*/export const SET_LOCATION_URL = 'SET_LOCATION_URL';+/**+ * The type of (redux) action which sets the preferVisitor in store.+ *+ * {+ * type: SET_PREFER_VISITOR,+ * preferVisitor: ?boolean+ * }+ */+export const SET_PREFER_VISITOR = 'SET_PREFER_VISITOR';+/*** The type of (redux) action which tells whether connection info should be displayed* on context menu.diff --git a/react/features/base/connection/actions.any.ts b/react/features/base/connection/actions.any.tsindex 286722a87c..2d5195c724 100644--- a/react/features/base/connection/actions.any.ts+++ b/react/features/base/connection/actions.any.ts@@ -16,7 +16,8 @@ import {CONNECTION_ESTABLISHED,CONNECTION_FAILED,CONNECTION_WILL_CONNECT,- SET_LOCATION_URL+ SET_LOCATION_URL,+ SET_PREFER_VISITOR} from './actionTypes';import { JITSI_CONNECTION_URL_KEY } from './constants';import logger from './logger';@@ -180,6 +181,22 @@ export function setLocationURL(locationURL?: URL) {};}+/**+ * To change prefer visitor in the store. Used later to decide what to request from jicofo on connection.+ *+ * @param {boolean} preferVisitor - The value to set.+ * @returns {{+ * type: SET_PREFER_VISITOR,+ * preferVisitor: boolean+ * }}+ */+export function setPreferVisitor(preferVisitor: boolean) {+ return {+ type: SET_PREFER_VISITOR,+ preferVisitor+ };+}+/*** Opens new connection.*diff --git a/react/features/base/connection/reducer.ts b/react/features/base/connection/reducer.tsindex bb734f1d63..2ebe4e229f 100644--- a/react/features/base/connection/reducer.ts+++ b/react/features/base/connection/reducer.ts@@ -10,6 +10,7 @@ import {CONNECTION_FAILED,CONNECTION_WILL_CONNECT,SET_LOCATION_URL,+ SET_PREFER_VISITOR,SHOW_CONNECTION_INFO} from './actionTypes';import { ConnectionFailedError } from './types';@@ -57,6 +58,11 @@ ReducerRegistry.register<IConnectionState>(case SET_LOCATION_URL:return _setLocationURL(state, action);+ case SET_PREFER_VISITOR:+ return assign(state, {+ preferVisitor: action.preferVisitor+ });+case SET_ROOM:return _setRoom(state);diff --git a/react/features/video-menu/components/index.web.ts b/react/features/video-menu/components/index.web.tsindex 36c5e0cd63..a90066218c 100644--- a/react/features/video-menu/components/index.web.ts+++ b/react/features/video-menu/components/index.web.ts@@ -1,3 +1,4 @@+export { default as DemoteToVisitorDialog } from './web/DemoteToVisitorDialog';export { default as GrantModeratorDialog } from './web/GrantModeratorDialog';export { default as KickRemoteParticipantDialog } from './web/KickRemoteParticipantDialog';export { default as MuteEveryoneDialog } from './web/MuteEveryoneDialog';diff --git a/react/features/video-menu/components/web/DemoteToVisitorButton.tsx b/react/features/video-menu/components/web/DemoteToVisitorButton.tsxnew file mode 100644index 0000000000..a0166c9df5--- /dev/null+++ b/react/features/video-menu/components/web/DemoteToVisitorButton.tsx@@ -0,0 +1,63 @@+import React, { useCallback } from 'react';+import { useTranslation } from 'react-i18next';+import { useDispatch } from 'react-redux';++import { openDialog } from '../../../base/dialog/actions';+import { IconUsers } from '../../../base/icons/svg';+import ContextMenuItem from '../../../base/ui/components/web/ContextMenuItem';+import { NOTIFY_CLICK_MODE } from '../../../toolbox/constants';+import { IButtonProps } from '../../types';++import DemoteToVisitorDialog from './DemoteToVisitorDialog';++interface IProps extends IButtonProps {++ /**+ * Button text class name.+ */+ className?: string;++ /**+ * Whether the icon should be hidden or not.+ */+ noIcon?: boolean;++ /**+ * Click handler executed aside from the main action.+ */+ onClick?: Function;+}++/**+ * Implements a React {@link Component} which displays a button for demoting a participant to visitor.+ *+ * @returns {JSX.Element}+ */+export default function DemoteToVisitorButton({+ className,+ noIcon = false,+ notifyClick,+ notifyMode,+ participantID+}: IProps): JSX.Element {+ const { t } = useTranslation();+ const dispatch = useDispatch();++ const handleClick = useCallback(() => {+ notifyClick?.();+ if (notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY) {+ return;+ }+ dispatch(openDialog(DemoteToVisitorDialog, { participantID }));+ }, [ dispatch, notifyClick, notifyMode, participantID ]);++ return (+ <ContextMenuItem+ accessibilityLabel = { t('videothumbnail.demote') }+ className = { className || 'demotelink' } // can be used in tests+ icon = { noIcon ? null : IconUsers }+ id = { `demotelink_${participantID}` }+ onClick = { handleClick }+ text = { t('videothumbnail.demote') } />+ );+}diff --git a/react/features/video-menu/components/web/DemoteToVisitorDialog.tsx b/react/features/video-menu/components/web/DemoteToVisitorDialog.tsxnew file mode 100644index 0000000000..b3b5c0d43e--- /dev/null+++ b/react/features/video-menu/components/web/DemoteToVisitorDialog.tsx@@ -0,0 +1,40 @@+import React, { useCallback } from 'react';+import { useTranslation } from 'react-i18next';+import { useDispatch } from 'react-redux';++import { DialogProps } from '../../../base/dialog/constants';+import Dialog from '../../../base/ui/components/web/Dialog';+import { demoteRequest } from '../../../visitors/actions';++interface IProps extends DialogProps {++ /**+ * The ID of the remote participant to be demoted.+ */+ participantID: string;+}++/**+ * Dialog to confirm a remote participant demote action.+ *+ * @returns {JSX.Element}+ */+export default function DemoteToVisitorDialog({ participantID }: IProps): JSX.Element {+ const { t } = useTranslation();+ const dispatch = useDispatch();++ const handleSubmit = useCallback(() => {+ dispatch(demoteRequest(participantID));+ }, [ dispatch, participantID ]);++ return (+ <Dialog+ ok = {{ translationKey: 'dialog.confirm' }}+ onSubmit = { handleSubmit }+ titleKey = 'dialog.demoteParticipantTitle'>+ <div>+ { t('dialog.demoteParticipantDialog') }+ </div>+ </Dialog>+ );+}diff --git a/react/features/video-menu/components/web/HideSelfViewVideoButton.tsx b/react/features/video-menu/components/web/HideSelfViewVideoButton.tsxindex 133e3e5d47..ac10a14371 100644--- a/react/features/video-menu/components/web/HideSelfViewVideoButton.tsx+++ b/react/features/video-menu/components/web/HideSelfViewVideoButton.tsx@@ -109,7 +109,7 @@ class HideSelfViewVideoButton extends PureComponent<IProps> {}/**- * Maps (parts of) the Redux state to the associated {@code FlipLocalVideoButton}'s props.+ * Maps (parts of) the Redux state to the associated {@code HideSelfViewVideoButton}'s props.** @param {Object} state - The Redux state.* @privatediff --git a/react/features/video-menu/components/web/LocalVideoMenuTriggerButton.tsx b/react/features/video-menu/components/web/LocalVideoMenuTriggerButton.tsxindex ec789a9edf..7a1599c453 100644--- a/react/features/video-menu/components/web/LocalVideoMenuTriggerButton.tsx+++ b/react/features/video-menu/components/web/LocalVideoMenuTriggerButton.tsx@@ -7,7 +7,7 @@ import { IReduxState, IStore } from '../../../app/types';import { getButtonNotifyMode, getParticipantMenuButtonsWithNotifyClick } from '../../../base/config/functions.web';import { isMobileBrowser } from '../../../base/environment/utils';import { IconDotsHorizontal } from '../../../base/icons/svg';-import { getLocalParticipant } from '../../../base/participants/functions';+import { getLocalParticipant, getParticipantCount } from '../../../base/participants/functions';import Popover from '../../../base/popover/components/Popover.web';import { setParticipantContextMenuOpen } from '../../../base/responsive-ui/actions';import { getHideSelfView } from '../../../base/settings/functions.web';@@ -23,6 +23,7 @@ import { renderConnectionStatus } from '../../actions.web';import { PARTICIPANT_MENU_BUTTONS as BUTTONS } from '../../constants';import ConnectionStatusButton from './ConnectionStatusButton';+import DemoteToVisitorButton from './DemoteToVisitorButton';import FlipLocalVideoButton from './FlipLocalVideoButton';import HideSelfViewVideoButton from './HideSelfViewVideoButton';import TogglePinToStageButton from './TogglePinToStageButton';@@ -54,6 +55,11 @@ interface IProps {*/_showConnectionInfo: boolean;+ /**+ * Shows/hides the local switch to visitor button.+ */+ _showDemote: boolean;+/*** Whether to render the hide self view button.*/@@ -131,6 +137,7 @@ const LocalVideoMenuTriggerButton = ({_menuPosition,_overflowDrawer,_showConnectionInfo,+ _showDemote,_showHideSelfViewButton,_showLocalVideoFlipButton,_showPinToStage,@@ -206,6 +213,16 @@ const LocalVideoMenuTriggerButton = ({onClick = { hidePopover }participantID = { _localParticipantId } />}+ {+ _showDemote && <DemoteToVisitorButton+ className = { _overflowDrawer ? classes.flipText : '' }+ noIcon = { true }+ // eslint-disable-next-line react/jsx-no-bind+ notifyClick = { () => notifyClick(BUTTONS.DEMOTE) }+ notifyMode = { getButtonNotifyMode(BUTTONS.DEMOTE, buttonsWithNotifyClick) }+ onClick = { hidePopover }+ participantID = { _localParticipantId } />+ }{isMobileBrowser() && <ConnectionStatusButton// eslint-disable-next-line react/jsx-no-bind@@ -274,6 +291,7 @@ function _mapStateToProps(state: IReduxState, ownProps: Partial<IProps>) {return {_menuPosition,+ _showDemote: getParticipantCount(state) > 1,_showLocalVideoFlipButton: !disableLocalVideoFlip && videoTrack?.videoType !== 'desktop',_showHideSelfViewButton: showHideSelfViewButton,_overflowDrawer: overflowDrawer,diff --git a/react/features/video-menu/components/web/ParticipantContextMenu.tsx b/react/features/video-menu/components/web/ParticipantContextMenu.tsxindex ae5da0cb35..3b83ce69a7 100644--- a/react/features/video-menu/components/web/ParticipantContextMenu.tsx+++ b/react/features/video-menu/components/web/ParticipantContextMenu.tsx@@ -31,6 +31,7 @@ import { PARTICIPANT_MENU_BUTTONS as BUTTONS } from '../../constants';import AskToUnmuteButton from './AskToUnmuteButton';import ConnectionStatusButton from './ConnectionStatusButton';import CustomOptionButton from './CustomOptionButton';+import DemoteToVisitorButton from './DemoteToVisitorButton';import GrantModeratorButton from './GrantModeratorButton';import KickButton from './KickButton';import MuteButton from './MuteButton';@@ -141,7 +142,7 @@ const ParticipantContextMenu = ({const { remoteVideoMenu = {}, disableRemoteMute, startSilent, customParticipantMenuButtons }= useSelector((state: IReduxState) => state['features/base/config']);const visitorsMode = useSelector((state: IReduxState) => iAmVisitor(state));- const { disableKick, disableGrantModerator, disablePrivateChat } = remoteVideoMenu;+ const { disableDemote, disableKick, disableGrantModerator, disablePrivateChat } = remoteVideoMenu;const { participantsVolume } = useSelector((state: IReduxState) => state['features/filmstrip']);const _volume = (participant?.local ?? true ? undefined: participant?.id ? participantsVolume[participant?.id] : undefined) ?? 1;@@ -245,6 +246,10 @@ const ParticipantContextMenu = ({buttons2.push(<GrantModeratorButton { ...getButtonProps(BUTTONS.GRANT_MODERATOR) } />);}+ if (!disableDemote && _isModerator) {+ buttons2.push(<DemoteToVisitorButton { ...getButtonProps(BUTTONS.DEMOTE) } />);+ }+if (!disableKick) {buttons2.push(<KickButton { ...getButtonProps(BUTTONS.KICK) } />);}diff --git a/react/features/video-menu/constants.ts b/react/features/video-menu/constants.tsindex 7c001cb94a..acf90fbf24 100644--- a/react/features/video-menu/constants.ts+++ b/react/features/video-menu/constants.ts@@ -20,6 +20,7 @@ export const PARTICIPANT_MENU_BUTTONS = {ALLOW_VIDEO: 'allow-video',ASK_UNMUTE: 'ask-unmute',CONN_STATUS: 'conn-status',+ DEMOTE: 'demote',FLIP_LOCAL_VIDEO: 'flip-local-video',GRANT_MODERATOR: 'grant-moderator',HIDE_SELF_VIEW: 'hide-self-view',diff --git a/react/features/visitors/actionTypes.ts b/react/features/visitors/actionTypes.tsindex 999e520a37..f8cef5d695 100644--- a/react/features/visitors/actionTypes.ts+++ b/react/features/visitors/actionTypes.ts@@ -38,3 +38,13 @@ export const VISITOR_PROMOTION_REQUEST = 'VISITOR_PROMOTION_REQUEST';* }*/export const CLEAR_VISITOR_PROMOTION_REQUEST = 'CLEAR_VISITOR_PROMOTION_REQUEST';++/**+ * The type of (redux) action which sets visitor demote actor.+ *+ * {+ * type: SET_VISITOR_DEMOTE_ACTOR,+ * displayName: string+ * }+ */+export const SET_VISITOR_DEMOTE_ACTOR = 'SET_VISITOR_DEMOTE_ACTOR';diff --git a/react/features/visitors/actions.ts b/react/features/visitors/actions.tsindex e88d5ce619..73414438b8 100644--- a/react/features/visitors/actions.ts+++ b/react/features/visitors/actions.ts@@ -1,9 +1,14 @@+import { createRemoteVideoMenuButtonEvent } from '../analytics/AnalyticsEvents';+import { sendAnalytics } from '../analytics/functions';import { IStore } from '../app/types';import { getCurrentConference } from '../base/conference/functions';+import { connect, disconnect, setPreferVisitor } from '../base/connection/actions';+import { getLocalParticipant } from '../base/participants/functions';import {CLEAR_VISITOR_PROMOTION_REQUEST,I_AM_VISITOR_MODE,+ SET_VISITOR_DEMOTE_ACTOR,UPDATE_VISITORS_COUNT,VISITOR_PROMOTION_REQUEST} from './actionTypes';@@ -70,6 +75,34 @@ export function denyRequest(request: IPromotionRequest) {};}+/**+ * Sends a demote request to a main participant to join the meeting as a visitor.+ *+ * @param {string} id - The ID for the participant.+ * @returns {Function}+ */+export function demoteRequest(id: string) {+ return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {+ const conference = getCurrentConference(getState);+ const localParticipant = getLocalParticipant(getState());++ sendAnalytics(createRemoteVideoMenuButtonEvent('demote.button', { 'participant_id': id }));++ if (id === localParticipant?.id) {+ dispatch(disconnect(true))+ .then(() => dispatch(setPreferVisitor(true)))+ .then(() => dispatch(connect()));+ } else {+ conference?.sendMessage({+ type: 'visitors',+ action: 'demote-request',+ id,+ actor: localParticipant?.id+ });+ }+ };+}+/*** Removes a promotion request from the state.*@@ -116,6 +149,21 @@ export function setIAmVisitor(enabled: boolean) {};}+/**+ * Sets visitor demote actor.+ *+ * @param {string|undefined} displayName - The display name of the participant.+ * @returns {{+ * type: SET_VISITOR_DEMOTE_ACTOR,+ * }}+ */+export function setVisitorDemoteActor(displayName: string | undefined) {+ return {+ type: SET_VISITOR_DEMOTE_ACTOR,+ displayName+ };+}+/*** Visitors count has been updated.*diff --git a/react/features/visitors/logger.ts b/react/features/visitors/logger.tsnew file mode 100644index 0000000000..56225e0f91--- /dev/null+++ b/react/features/visitors/logger.ts@@ -0,0 +1,3 @@+import { getLogger } from '../base/logging/functions';++export default getLogger('features/visitors');diff --git a/react/features/visitors/middleware.ts b/react/features/visitors/middleware.tsindex 0811e012bf..591eda3bac 100644--- a/react/features/visitors/middleware.ts+++ b/react/features/visitors/middleware.ts@@ -7,8 +7,11 @@ import {CONFERENCE_JOIN_IN_PROGRESS,ENDPOINT_MESSAGE_RECEIVED} from '../base/conference/actionTypes';+import { connect, setPreferVisitor } from '../base/connection/actions';+import { disconnect } from '../base/connection/actions.any';import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';import { raiseHand } from '../base/participants/actions';+import { getParticipantById } from '../base/participants/functions';import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';import { BUTTON_TYPES } from '../base/ui/constants.any';import { hideNotification, showNotification } from '../notifications/actions';@@ -17,6 +20,7 @@ import {NOTIFICATION_TIMEOUT_TYPE,VISITORS_PROMOTION_NOTIFICATION_ID} from '../notifications/constants';+import { INotificationProps } from '../notifications/types';import { open as openParticipantsPane } from '../participants-pane/actions';import {@@ -24,9 +28,11 @@ import {clearPromotionRequest,denyRequest,promotionRequestReceived,+ setVisitorDemoteActor,updateVisitorsCount} from './actions';import { getPromotionRequests } from './functions';+import logger from './logger';MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {switch (action.type) {@@ -46,28 +52,62 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {const { conference } = action;if (getState()['features/visitors'].iAmVisitor) {- dispatch(showNotification({+ const { demoteActorDisplayName } = getState()['features/visitors'];++ dispatch(setVisitorDemoteActor(undefined));++ const notificationParams: INotificationProps = {titleKey: 'visitors.notification.title',descriptionKey: 'visitors.notification.description'- }, NOTIFICATION_TIMEOUT_TYPE.STICKY));+ };++ if (demoteActorDisplayName) {+ notificationParams.descriptionKey = 'visitors.notification.demoteDescription';+ notificationParams.descriptionArguments = {+ actor: demoteActorDisplayName+ };+ }++ // check for demote actor and update notification+ dispatch(showNotification(notificationParams, NOTIFICATION_TIMEOUT_TYPE.STICKY));}conference.on(JitsiConferenceEvents.VISITORS_MESSAGE, (- msg: { from: string; nick: string; on: boolean; }) => {- const request = {- from: msg.from,- nick: msg.nick- };-- if (msg.on) {- dispatch(promotionRequestReceived(request));+ msg: { action: string; actor: string; from: string; nick: string; on: boolean; }) => {++ if (msg.action === 'demote-request') {+ // we need it before the disconnect+ const participantById = getParticipantById(getState, msg.actor);++ // handle demote+ dispatch(disconnect(true))+ .then(() => dispatch(setPreferVisitor(true)))+ .then(() => {+ // we need to set the name so we can use it later in the notification+ if (participantById) {+ dispatch(setVisitorDemoteActor(participantById.name));+ }++ return dispatch(connect());+ });+ } else if (msg.action === 'promotion-request') {+ const request = {+ from: msg.from,+ nick: msg.nick+ };++ if (msg.on) {+ dispatch(promotionRequestReceived(request));+ } else {+ dispatch(clearPromotionRequest(request));+ }+ _handlePromotionNotification({+ dispatch,+ getState+ });} else {- dispatch(clearPromotionRequest(request));+ logger.error('Unknown action:', msg.action);}- _handlePromotionNotification({- dispatch,- getState- });});conference.on(JitsiConferenceEvents.VISITORS_REJECTION, () => {diff --git a/react/features/visitors/reducer.ts b/react/features/visitors/reducer.tsindex d02e622b94..d5bbc33ac1 100644--- a/react/features/visitors/reducer.ts+++ b/react/features/visitors/reducer.ts@@ -4,6 +4,7 @@ import ReducerRegistry from '../base/redux/ReducerRegistry';import {CLEAR_VISITOR_PROMOTION_REQUEST,I_AM_VISITOR_MODE,+ SET_VISITOR_DEMOTE_ACTOR,UPDATE_VISITORS_COUNT,VISITOR_PROMOTION_REQUEST} from './actionTypes';@@ -18,6 +19,7 @@ const DEFAULT_STATE = {export interface IVisitorsState {count?: number;+ demoteActorDisplayName?: string;iAmVisitor: boolean;promotionRequests: IPromotionRequest[];}@@ -50,6 +52,12 @@ ReducerRegistry.register<IVisitorsState>('features/visitors', (state = DEFAULT_SiAmVisitor: action.enabled};}+ case SET_VISITOR_DEMOTE_ACTOR: {+ return {+ ...state,+ demoteActorDisplayName: action.displayName+ };+ }case VISITOR_PROMOTION_REQUEST: {const currentRequests = state.promotionRequests || [];diff --git a/resources/prosody-plugins/mod_visitors_component.lua b/resources/prosody-plugins/mod_visitors_component.luaindex 705ead87b4..c56e79c315 100644--- a/resources/prosody-plugins/mod_visitors_component.lua+++ b/resources/prosody-plugins/mod_visitors_component.lua@@ -379,7 +379,8 @@ process_host_module(muc_domain_prefix..'.'..muc_domain_base, function(host_modulreturn;endlocal data = json.decode(json_data);- if not data or data.type ~= 'visitors' or data.action ~= "promotion-response" then+ if not data or data.type ~= 'visitors'+ or (data.action ~= "promotion-response" and data.action ~= "demote-request") thenreturn;end@@ -397,12 +398,37 @@ process_host_module(muc_domain_prefix..'.'..muc_domain_base, function(host_modulreturn false;end- if data.id then- process_promotion_response(room, data.id, data.approved and 'true' or 'false');+ if data.action == "demote-request" then+ if occupant.nick ~= room.jid..'/'..data.actor then+ module:log('error', 'Bad actor in demote request %s', stanza);+ event.origin.send(st.error_reply(stanza, "cancel", "bad-request"));+ return true;+ end++ -- when demoting we want to send message to the demoted participant and to moderators+ local target_jid = room.jid..'/'..data.id;+ stanza.attr.type = 'chat'; -- it is safe as we are not using this stanza instance anymore+ stanza.attr.from = module.host;++ for _, room_occupant in room:each_occupant() do+ -- do not send it to jicofo or back to the sender+ if room_occupant.jid ~= occupant.jid and not is_admin(room_occupant.bare_jid) then+ if room_occupant.role == 'moderator'+ or room_occupant.nick == target_jid then+ stanza.attr.to = room_occupant.jid;+ room:route_stanza(stanza);+ end+ end+ end+else- -- we are in the case with admit all, we need to read data.ids- for i in pairs(data.ids) do+ if data.id thenprocess_promotion_response(room, data.id, data.approved and 'true' or 'false');+ else+ -- we are in the case with admit all, we need to read data.ids+ for i in pairs(data.ids) do+ process_promotion_response(room, data.id, data.approved and 'true' or 'false');+ endendend