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 7.3KB

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