您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractMuteEveryoneDialog.ts 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. import { muteAllParticipants } from '../actions';
  8. import AbstractMuteRemoteParticipantDialog, {
  9. type Props as AbstractProps
  10. } from './AbstractMuteRemoteParticipantDialog';
  11. /**
  12. * The type of the React {@code Component} props of
  13. * {@link AbstractMuteEveryoneDialog}.
  14. */
  15. export type Props = AbstractProps & WithTranslation & {
  16. content: string;
  17. exclude: Array<string>;
  18. isAudioModerationEnabled: 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 Props> 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 {Props}
  98. */
  99. export function abstractMapStateToProps(state: IReduxState, ownProps: Props) {
  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. } : {
  111. title: t('dialog.muteEveryoneTitle'),
  112. isAudioModerationEnabled: isEnabledFromState(MEDIA_TYPE.AUDIO, state),
  113. isModerationSupported: isSupported()(state)
  114. };
  115. }