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

AbstractMuteEveryoneDialog.ts 4.2KB

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