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.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // @flow
  2. import React from 'react';
  3. import { requestDisableAudioModeration, requestEnableAudioModeration } from '../../av-moderation/actions';
  4. import { isEnabledFromState, isSupported } from '../../av-moderation/functions';
  5. import { Dialog } from '../../base/dialog';
  6. import { MEDIA_TYPE } from '../../base/media';
  7. import { getLocalParticipant, getParticipantDisplayName } from '../../base/participants';
  8. import { muteAllParticipants } from '../actions';
  9. import AbstractMuteRemoteParticipantDialog, {
  10. type Props as AbstractProps
  11. } from './AbstractMuteRemoteParticipantDialog';
  12. /**
  13. * The type of the React {@code Component} props of
  14. * {@link AbstractMuteEveryoneDialog}.
  15. */
  16. export type Props = AbstractProps & {
  17. content: string,
  18. exclude: Array<string>,
  19. title: string,
  20. showAdvancedModerationToggle: boolean,
  21. isAudioModerationEnabled: boolean,
  22. isModerationSupported: boolean
  23. };
  24. type State = {
  25. audioModerationEnabled: boolean,
  26. content: string
  27. };
  28. /**
  29. *
  30. * An abstract Component with the contents for a dialog that asks for confirmation
  31. * from the user before muting all remote participants.
  32. *
  33. * @extends AbstractMuteRemoteParticipantDialog
  34. */
  35. export default class AbstractMuteEveryoneDialog<P: Props> extends AbstractMuteRemoteParticipantDialog<P, State> {
  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. * Implements React's {@link Component#render()}.
  60. *
  61. * @inheritdoc
  62. * @returns {ReactElement}
  63. */
  64. render() {
  65. const { content, title } = this.props;
  66. return (
  67. <Dialog
  68. okKey = 'dialog.muteParticipantButton'
  69. onSubmit = { this._onSubmit }
  70. titleString = { title }
  71. width = 'small'>
  72. <div>
  73. { content }
  74. </div>
  75. </Dialog>
  76. );
  77. }
  78. _onSubmit: () => boolean;
  79. _onToggleModeration: () => void;
  80. /**
  81. * Callback to be invoked when the value of this dialog is submitted.
  82. *
  83. * @returns {boolean}
  84. */
  85. _onSubmit() {
  86. const {
  87. dispatch,
  88. exclude
  89. } = this.props;
  90. dispatch(muteAllParticipants(exclude, MEDIA_TYPE.AUDIO));
  91. if (this.state.audioModerationEnabled) {
  92. dispatch(requestEnableAudioModeration());
  93. } else if (this.state.audioModerationEnabled !== undefined) {
  94. dispatch(requestDisableAudioModeration());
  95. }
  96. return true;
  97. }
  98. }
  99. /**
  100. * Maps (parts of) the Redux state to the associated {@code AbstractMuteEveryoneDialog}'s props.
  101. *
  102. * @param {Object} state - The redux state.
  103. * @param {Object} ownProps - The properties explicitly passed to the component.
  104. * @returns {Props}
  105. */
  106. export function abstractMapStateToProps(state: Object, ownProps: Props) {
  107. const { exclude = [], t } = ownProps;
  108. const whom = exclude
  109. // eslint-disable-next-line no-confusing-arrow
  110. .map(id => id === getLocalParticipant(state).id
  111. ? t('dialog.muteEveryoneSelf')
  112. : getParticipantDisplayName(state, id))
  113. .join(', ');
  114. return whom.length ? {
  115. content: t('dialog.muteEveryoneElseDialog'),
  116. title: t('dialog.muteEveryoneElseTitle', { whom })
  117. } : {
  118. title: t('dialog.muteEveryoneTitle'),
  119. isAudioModerationEnabled: isEnabledFromState(MEDIA_TYPE.AUDIO, state),
  120. isModerationSupported: isSupported()(state)
  121. };
  122. }