Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AbstractMuteEveryoneDialog.ts 4.1KB

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