Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AbstractMuteEveryoneDialog.ts 4.0KB

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