You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractMuteEveryoneDialog.ts 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { IReduxState } from '../../app/types';
  2. import { requestDisableAudioModeration, requestEnableAudioModeration } from '../../av-moderation/actions';
  3. import { isEnabledFromState, isSupported } from '../../av-moderation/functions';
  4. import { MEDIA_TYPE } from '../../base/media/constants';
  5. import { getLocalParticipant, getParticipantDisplayName, isEveryoneModerator } from '../../base/participants/functions';
  6. import { muteAllParticipants } from '../actions';
  7. import AbstractMuteRemoteParticipantDialog, {
  8. type IProps as AbstractProps
  9. } from './AbstractMuteRemoteParticipantDialog';
  10. /**
  11. * The type of the React {@code Component} props of
  12. * {@link AbstractMuteEveryoneDialog}.
  13. */
  14. export interface IProps extends AbstractProps {
  15. content?: string;
  16. exclude: Array<string>;
  17. isAudioModerationEnabled?: boolean;
  18. isEveryoneModerator: boolean;
  19. isModerationSupported?: boolean;
  20. showAdvancedModerationToggle: boolean;
  21. title: string;
  22. }
  23. interface IState {
  24. audioModerationEnabled?: boolean;
  25. content: string;
  26. }
  27. /**
  28. *
  29. * An abstract Component with the contents for a dialog that asks for confirmation
  30. * from the user before muting all remote participants.
  31. *
  32. * @augments AbstractMuteRemoteParticipantDialog
  33. */
  34. export default class AbstractMuteEveryoneDialog<P extends IProps> extends
  35. AbstractMuteRemoteParticipantDialog<P, IState> {
  36. static defaultProps = {
  37. exclude: [],
  38. muteLocal: false
  39. };
  40. /**
  41. * Initializes a new {@code AbstractMuteRemoteParticipantDialog} instance.
  42. *
  43. * @param {Object} props - The read-only properties with which the new
  44. * instance is to be initialized.
  45. */
  46. constructor(props: P) {
  47. super(props);
  48. this.state = {
  49. audioModerationEnabled: props.isAudioModerationEnabled,
  50. content: props.content || props.t(props.isAudioModerationEnabled
  51. ? 'dialog.muteEveryoneDialogModerationOn' : 'dialog.muteEveryoneDialog'
  52. )
  53. };
  54. // Bind event handlers so they are only bound once per instance.
  55. this._onSubmit = this._onSubmit.bind(this);
  56. this._onToggleModeration = this._onToggleModeration.bind(this);
  57. }
  58. /**
  59. * Toggles advanced moderation switch.
  60. *
  61. * @returns {void}
  62. */
  63. _onToggleModeration() {
  64. this.setState(state => {
  65. return {
  66. audioModerationEnabled: !state.audioModerationEnabled,
  67. content: this.props.t(state.audioModerationEnabled
  68. ? 'dialog.muteEveryoneDialog' : 'dialog.muteEveryoneDialogModerationOn'
  69. )
  70. };
  71. });
  72. }
  73. /**
  74. * Callback to be invoked when the value of this dialog is submitted.
  75. *
  76. * @returns {boolean}
  77. */
  78. _onSubmit() {
  79. const {
  80. dispatch,
  81. exclude
  82. } = this.props;
  83. dispatch(muteAllParticipants(exclude, MEDIA_TYPE.AUDIO));
  84. if (this.state.audioModerationEnabled) {
  85. dispatch(requestEnableAudioModeration());
  86. } else if (this.state.audioModerationEnabled !== undefined) {
  87. dispatch(requestDisableAudioModeration());
  88. }
  89. return true;
  90. }
  91. }
  92. /**
  93. * Maps (parts of) the Redux state to the associated {@code AbstractMuteEveryoneDialog}'s props.
  94. *
  95. * @param {IReduxState} state - The redux state.
  96. * @param {Object} ownProps - The properties explicitly passed to the component.
  97. * @returns {IProps}
  98. */
  99. export function abstractMapStateToProps(state: IReduxState, ownProps: IProps) {
  100. const { exclude = [], t } = ownProps;
  101. const whom = exclude
  102. // eslint-disable-next-line no-confusing-arrow
  103. .map(id => id === getLocalParticipant(state)?.id
  104. ? t('dialog.muteEveryoneSelf')
  105. : getParticipantDisplayName(state, id))
  106. .join(', ');
  107. return whom.length ? {
  108. content: t('dialog.muteEveryoneElseDialog'),
  109. title: t('dialog.muteEveryoneElseTitle', { whom }),
  110. isEveryoneModerator: isEveryoneModerator(state)
  111. } : {
  112. title: t('dialog.muteEveryoneTitle'),
  113. isAudioModerationEnabled: isEnabledFromState(MEDIA_TYPE.AUDIO, state),
  114. isModerationSupported: isSupported()(state),
  115. isEveryoneModerator: isEveryoneModerator(state)
  116. };
  117. }