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.

KnockingParticipantList.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { ScrollView, Text, View, TouchableOpacity } from 'react-native';
  4. import { Avatar } from '../../../base/avatar';
  5. import { translate } from '../../../base/i18n';
  6. import { isLocalParticipantModerator } from '../../../base/participants';
  7. import { connect } from '../../../base/redux';
  8. import { handleLobbyChatInitialized } from '../../../chat/actions.any';
  9. import { navigate } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  10. import { screen } from '../../../mobile/navigation/routes';
  11. import { setKnockingParticipantApproval } from '../../actions';
  12. import { HIDDEN_EMAILS } from '../../constants';
  13. import { showLobbyChatButton, getKnockingParticipants, getLobbyEnabled } from '../../functions';
  14. import styles from './styles';
  15. /**
  16. * Props type of the component.
  17. */
  18. export type Props = {
  19. /**
  20. * The list of participants.
  21. */
  22. _participants: Array<Object>,
  23. /**
  24. * True if the list should be rendered.
  25. */
  26. _visible: boolean,
  27. /**
  28. * True if the polls feature is disabled.
  29. */
  30. _isPollsDisabled: boolean,
  31. /**
  32. * Returns true if the lobby chat button should be shown.
  33. */
  34. _showChatButton: Function,
  35. /**
  36. * The Redux Dispatch function.
  37. */
  38. dispatch: Function,
  39. /**
  40. * Function to be used to translate i18n labels.
  41. */
  42. t: Function
  43. };
  44. /**
  45. * Component to render a list for the actively knocking participants.
  46. */
  47. class KnockingParticipantList extends PureComponent<Props> {
  48. /**
  49. * Instantiates a new component.
  50. *
  51. * @param {Object} props - The read-only properties with which the new
  52. * instance is to be initialized.
  53. */
  54. constructor(props: Props) {
  55. super(props);
  56. this._onRespondToParticipant = this._onRespondToParticipant.bind(this);
  57. }
  58. /**
  59. * Implements {@code PureComponent#render}.
  60. *
  61. * @inheritdoc
  62. */
  63. render() {
  64. const { _participants, _visible, _showChatButton, t } = this.props;
  65. if (!_visible) {
  66. return null;
  67. }
  68. return (
  69. <ScrollView
  70. style = { styles.knockingParticipantList }>
  71. { _participants.map(p => (
  72. <View
  73. key = { p.id }
  74. style = { styles.knockingParticipantListEntry }>
  75. <Avatar
  76. displayName = { p.name }
  77. size = { 48 }
  78. url = { p.loadableAvatarUrl } />
  79. <View style = { styles.knockingParticipantListDetails }>
  80. <Text style = { styles.knockingParticipantListText }>
  81. { p.name }
  82. </Text>
  83. { p.email && !HIDDEN_EMAILS.includes(p.email) && (
  84. <Text style = { styles.knockingParticipantListText }>
  85. { p.email }
  86. </Text>
  87. ) }
  88. </View>
  89. <TouchableOpacity
  90. onPress = { this._onRespondToParticipant(p.id, true) }
  91. style = { [
  92. styles.knockingParticipantListButton,
  93. styles.knockingParticipantListPrimaryButton
  94. ] }>
  95. <Text style = { styles.knockingParticipantListText }>
  96. { t('lobby.allow') }
  97. </Text>
  98. </TouchableOpacity>
  99. <TouchableOpacity
  100. onPress = { this._onRespondToParticipant(p.id, false) }
  101. style = { [
  102. styles.knockingParticipantListButton,
  103. styles.knockingParticipantListSecondaryButton
  104. ] }>
  105. <Text style = { styles.knockingParticipantListText }>
  106. { t('lobby.reject') }
  107. </Text>
  108. </TouchableOpacity>
  109. {_showChatButton(p) ? (
  110. <TouchableOpacity
  111. onPress = { this._onInitializeLobbyChat(p.id) }
  112. style = { [
  113. styles.knockingParticipantListButton,
  114. styles.knockingParticipantListSecondaryButton
  115. ] }>
  116. <Text style = { styles.knockingParticipantListText }>
  117. { t('lobby.chat') }
  118. </Text>
  119. </TouchableOpacity>
  120. ) : null}
  121. </View>
  122. )) }
  123. </ScrollView>
  124. );
  125. }
  126. _onRespondToParticipant: (string, boolean) => Function;
  127. /**
  128. * Function that constructs a callback for the response handler button.
  129. *
  130. * @param {string} id - The id of the knocking participant.
  131. * @param {boolean} approve - The response for the knocking.
  132. * @returns {Function}
  133. */
  134. _onRespondToParticipant(id, approve) {
  135. return () => {
  136. this.props.dispatch(setKnockingParticipantApproval(id, approve));
  137. };
  138. }
  139. _onInitializeLobbyChat: (string) => Function;
  140. /**
  141. * Function that constructs a callback for the lobby chat button.
  142. *
  143. * @param {string} id - The id of the knocking participant.
  144. * @returns {Function}
  145. */
  146. _onInitializeLobbyChat(id) {
  147. return () => {
  148. this.props.dispatch(handleLobbyChatInitialized(id));
  149. if (this.props._isPollsDisabled) {
  150. return navigate(screen.conference.chat);
  151. }
  152. navigate(screen.conference.chatandpolls.main);
  153. };
  154. }
  155. }
  156. /**
  157. * Maps part of the Redux state to the props of this component.
  158. *
  159. * @param {Object} state - The Redux state.
  160. * @returns {Props}
  161. */
  162. function _mapStateToProps(state): Object {
  163. const lobbyEnabled = getLobbyEnabled(state);
  164. const knockingParticipants = getKnockingParticipants(state);
  165. const { disablePolls } = state['features/base/config'];
  166. return {
  167. _visible: lobbyEnabled && isLocalParticipantModerator(state),
  168. _showChatButton: participant => showLobbyChatButton(participant)(state),
  169. _isPollsDisabled: disablePolls,
  170. // On mobile we only show a portion of the list for screen real estate reasons
  171. _participants: knockingParticipants.slice(0, 2)
  172. };
  173. }
  174. export default translate(connect(_mapStateToProps)(KnockingParticipantList));