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.

AbstractAddPeopleDialog.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // @flow
  2. import { Component } from 'react';
  3. import { createInviteDialogEvent, sendAnalytics } from '../../../analytics';
  4. import { invite } from '../../actions';
  5. import {
  6. getInviteResultsForQuery,
  7. getInviteTypeCounts,
  8. isAddPeopleEnabled,
  9. isDialOutEnabled
  10. } from '../../functions';
  11. const logger = require('jitsi-meet-logger').getLogger(__filename);
  12. export type Props = {
  13. /**
  14. * Whether or not to show Add People functionality.
  15. */
  16. _addPeopleEnabled: boolean,
  17. /**
  18. * The URL for validating if a phone number can be called.
  19. */
  20. _dialOutAuthUrl: string,
  21. /**
  22. * Whether or not to show Dial Out functionality.
  23. */
  24. _dialOutEnabled: boolean,
  25. /**
  26. * The JWT token.
  27. */
  28. _jwt: string,
  29. /**
  30. * The query types used when searching people.
  31. */
  32. _peopleSearchQueryTypes: Array<string>,
  33. /**
  34. * The URL pointing to the service allowing for people search.
  35. */
  36. _peopleSearchUrl: string,
  37. /**
  38. * The Redux dispatch function.
  39. */
  40. dispatch: Function
  41. };
  42. export type State = {
  43. /**
  44. * Indicating that an error occurred when adding people to the call.
  45. */
  46. addToCallError: boolean,
  47. /**
  48. * Indicating that we're currently adding the new people to the
  49. * call.
  50. */
  51. addToCallInProgress: boolean,
  52. /**
  53. * The list of invite items.
  54. */
  55. inviteItems: Array<Object>,
  56. };
  57. /**
  58. * Implements an abstract dialog to invite people to the conference.
  59. */
  60. export default class AbstractAddPeopleDialog<P: Props, S: State>
  61. extends Component<P, S> {
  62. /**
  63. * Constructor of the component.
  64. *
  65. * @inheritdoc
  66. */
  67. constructor(props: P) {
  68. super(props);
  69. this._query = this._query.bind(this);
  70. }
  71. /**
  72. * Invite people and numbers to the conference. The logic works by inviting
  73. * numbers, people/rooms, and videosipgw in parallel. All invitees are
  74. * stored in an array. As each invite succeeds, the invitee is removed
  75. * from the array. After all invites finish, close the modal if there are
  76. * no invites left to send. If any are left, that means an invite failed
  77. * and an error state should display.
  78. *
  79. * @param {Array<Object>} invitees - The items to be invited.
  80. * @returns {Promise<Array<Object>>}
  81. */
  82. _invite(invitees) {
  83. const inviteTypeCounts = getInviteTypeCounts(invitees);
  84. sendAnalytics(createInviteDialogEvent(
  85. 'clicked', 'inviteButton', {
  86. ...inviteTypeCounts,
  87. inviteAllowed: this._isAddDisabled()
  88. }));
  89. if (this._isAddDisabled()) {
  90. return Promise.resolve([]);
  91. }
  92. this.setState({
  93. addToCallInProgress: true
  94. });
  95. const { dispatch } = this.props;
  96. return dispatch(invite(invitees))
  97. .then(invitesLeftToSend => {
  98. this.setState({
  99. addToCallInProgress: false
  100. });
  101. // If any invites are left that means something failed to send
  102. // so treat it as an error.
  103. if (invitesLeftToSend.length) {
  104. const erroredInviteTypeCounts
  105. = getInviteTypeCounts(invitesLeftToSend);
  106. logger.error(`${invitesLeftToSend.length} invites failed`,
  107. erroredInviteTypeCounts);
  108. sendAnalytics(createInviteDialogEvent(
  109. 'error', 'invite', {
  110. ...erroredInviteTypeCounts
  111. }));
  112. this.setState({
  113. addToCallError: true
  114. });
  115. }
  116. return invitesLeftToSend;
  117. });
  118. }
  119. /**
  120. * Indicates if the Add button should be disabled.
  121. *
  122. * @private
  123. * @returns {boolean} - True to indicate that the Add button should
  124. * be disabled, false otherwise.
  125. */
  126. _isAddDisabled() {
  127. return !this.state.inviteItems.length
  128. || this.state.addToCallInProgress;
  129. }
  130. _query: (?string) => Promise<Array<Object>>;
  131. /**
  132. * Performs a people and phone number search request.
  133. *
  134. * @param {string} query - The search text.
  135. * @private
  136. * @returns {Promise}
  137. */
  138. _query(query = '') {
  139. const {
  140. _addPeopleEnabled: addPeopleEnabled,
  141. _dialOutAuthUrl: dialOutAuthUrl,
  142. _dialOutEnabled: dialOutEnabled,
  143. _jwt: jwt,
  144. _peopleSearchQueryTypes: peopleSearchQueryTypes,
  145. _peopleSearchUrl: peopleSearchUrl
  146. } = this.props;
  147. const options = {
  148. addPeopleEnabled,
  149. dialOutAuthUrl,
  150. dialOutEnabled,
  151. jwt,
  152. peopleSearchQueryTypes,
  153. peopleSearchUrl
  154. };
  155. return getInviteResultsForQuery(query, options);
  156. }
  157. }
  158. /**
  159. * Maps (parts of) the Redux state to the props of this component.
  160. *
  161. * @param {Object} state - The Redux state.
  162. * @private
  163. * @returns {{
  164. * _addPeopleEnabled: boolean,
  165. * _dialOutAuthUrl: string,
  166. * _dialOutEnabled: boolean,
  167. * _jwt: string,
  168. * _peopleSearchQueryTypes: Array<string>,
  169. * _peopleSearchUrl: string
  170. * }}
  171. */
  172. export function _mapStateToProps(state: Object) {
  173. const {
  174. dialOutAuthUrl,
  175. peopleSearchQueryTypes,
  176. peopleSearchUrl
  177. } = state['features/base/config'];
  178. return {
  179. _addPeopleEnabled: isAddPeopleEnabled(state),
  180. _dialOutAuthUrl: dialOutAuthUrl,
  181. _dialOutEnabled: isDialOutEnabled(state),
  182. _jwt: state['features/base/jwt'].jwt,
  183. _peopleSearchQueryTypes: peopleSearchQueryTypes,
  184. _peopleSearchUrl: peopleSearchUrl
  185. };
  186. }