2020-11-10 14:49:38 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
import { requestDisableAudioModeration, requestEnableAudioModeration } from '../../av-moderation/actions';
|
2021-10-01 13:47:13 +00:00
|
|
|
import { isEnabledFromState, isSupported } from '../../av-moderation/functions';
|
2020-11-10 14:49:38 +00:00
|
|
|
import { Dialog } from '../../base/dialog';
|
2021-02-24 21:45:07 +00:00
|
|
|
import { MEDIA_TYPE } from '../../base/media';
|
2020-11-10 14:49:38 +00:00
|
|
|
import { getLocalParticipant, getParticipantDisplayName } from '../../base/participants';
|
|
|
|
import { muteAllParticipants } from '../actions';
|
|
|
|
|
|
|
|
import AbstractMuteRemoteParticipantDialog, {
|
|
|
|
type Props as AbstractProps
|
|
|
|
} from './AbstractMuteRemoteParticipantDialog';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link AbstractMuteEveryoneDialog}.
|
|
|
|
*/
|
|
|
|
export type Props = AbstractProps & {
|
|
|
|
|
|
|
|
content: string,
|
|
|
|
exclude: Array<string>,
|
2021-09-10 11:05:16 +00:00
|
|
|
title: string,
|
|
|
|
showAdvancedModerationToggle: boolean,
|
2021-10-01 13:47:13 +00:00
|
|
|
isAudioModerationEnabled: boolean,
|
|
|
|
isModerationSupported: boolean
|
2021-09-10 11:05:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
audioModerationEnabled: boolean,
|
|
|
|
content: string
|
2020-11-10 14:49:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* An abstract Component with the contents for a dialog that asks for confirmation
|
|
|
|
* from the user before muting all remote participants.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments AbstractMuteRemoteParticipantDialog
|
2020-11-10 14:49:38 +00:00
|
|
|
*/
|
2021-09-10 11:05:16 +00:00
|
|
|
export default class AbstractMuteEveryoneDialog<P: Props> extends AbstractMuteRemoteParticipantDialog<P, State> {
|
2020-11-10 14:49:38 +00:00
|
|
|
static defaultProps = {
|
|
|
|
exclude: [],
|
|
|
|
muteLocal: false
|
|
|
|
};
|
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code AbstractMuteRemoteParticipantDialog} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props: P) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
audioModerationEnabled: props.isAudioModerationEnabled,
|
|
|
|
content: props.content || props.t(props.isAudioModerationEnabled
|
|
|
|
? 'dialog.muteEveryoneDialogModerationOn' : 'dialog.muteEveryoneDialog'
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onSubmit = this._onSubmit.bind(this);
|
|
|
|
this._onToggleModeration = this._onToggleModeration.bind(this);
|
|
|
|
}
|
|
|
|
|
2020-11-10 14:49:38 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { content, title } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog
|
|
|
|
okKey = 'dialog.muteParticipantButton'
|
|
|
|
onSubmit = { this._onSubmit }
|
|
|
|
titleString = { title }
|
|
|
|
width = 'small'>
|
|
|
|
<div>
|
|
|
|
{ content }
|
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onSubmit: () => boolean;
|
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
_onToggleModeration: () => void;
|
|
|
|
|
2020-11-10 14:49:38 +00:00
|
|
|
/**
|
|
|
|
* Callback to be invoked when the value of this dialog is submitted.
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_onSubmit() {
|
|
|
|
const {
|
|
|
|
dispatch,
|
|
|
|
exclude
|
|
|
|
} = this.props;
|
|
|
|
|
2021-02-24 21:45:07 +00:00
|
|
|
dispatch(muteAllParticipants(exclude, MEDIA_TYPE.AUDIO));
|
2021-09-10 11:05:16 +00:00
|
|
|
if (this.state.audioModerationEnabled) {
|
|
|
|
dispatch(requestEnableAudioModeration());
|
2021-09-22 12:25:55 +00:00
|
|
|
} else if (this.state.audioModerationEnabled !== undefined) {
|
2021-09-10 11:05:16 +00:00
|
|
|
dispatch(requestDisableAudioModeration());
|
|
|
|
}
|
2020-11-10 14:49:38 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated {@code AbstractMuteEveryoneDialog}'s props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @param {Object} ownProps - The properties explicitly passed to the component.
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
export function abstractMapStateToProps(state: Object, ownProps: Props) {
|
2021-04-21 13:48:05 +00:00
|
|
|
const { exclude = [], t } = ownProps;
|
2020-11-10 14:49:38 +00:00
|
|
|
|
|
|
|
const whom = exclude
|
|
|
|
// eslint-disable-next-line no-confusing-arrow
|
|
|
|
.map(id => id === getLocalParticipant(state).id
|
|
|
|
? t('dialog.muteEveryoneSelf')
|
|
|
|
: getParticipantDisplayName(state, id))
|
|
|
|
.join(', ');
|
|
|
|
|
|
|
|
return whom.length ? {
|
|
|
|
content: t('dialog.muteEveryoneElseDialog'),
|
|
|
|
title: t('dialog.muteEveryoneElseTitle', { whom })
|
|
|
|
} : {
|
2021-09-10 11:05:16 +00:00
|
|
|
title: t('dialog.muteEveryoneTitle'),
|
2021-10-01 13:47:13 +00:00
|
|
|
isAudioModerationEnabled: isEnabledFromState(MEDIA_TYPE.AUDIO, state),
|
|
|
|
isModerationSupported: isSupported()(state)
|
2020-11-10 14:49:38 +00:00
|
|
|
};
|
|
|
|
}
|