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.

functions.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @flow
  2. declare var $: Function;
  3. declare var interfaceConfig: Object;
  4. /**
  5. * Get the position of the invite option in the interfaceConfig.INVITE_OPTIONS
  6. * list.
  7. *
  8. * @param {string} name - The invite option name.
  9. * @private
  10. * @returns {number} - The position of the option in the list.
  11. */
  12. export function getInviteOptionPosition(name: string): number {
  13. return interfaceConfig.INVITE_OPTIONS.indexOf(name);
  14. }
  15. /**
  16. * Sends a post request to an invite service.
  17. *
  18. * @param {string} inviteServiceUrl - The invite service that generates the
  19. * invitation.
  20. * @param {string} inviteUrl - The url to the conference.
  21. * @param {string} jwt - The jwt token to pass to the search service.
  22. * @param {Immutable.List} inviteItems - The list of the "user" or "room"
  23. * type items to invite.
  24. * @returns {Promise} - The promise created by the request.
  25. */
  26. export function invitePeopleAndChatRooms( // eslint-disable-line max-params
  27. inviteServiceUrl: string,
  28. inviteUrl: string,
  29. jwt: string,
  30. inviteItems: Object) {
  31. if (!inviteItems || inviteItems.length === 0) {
  32. return Promise.resolve();
  33. }
  34. return new Promise((resolve, reject) => {
  35. $.post(
  36. `${inviteServiceUrl}?token=${jwt}`,
  37. JSON.stringify({
  38. 'invited': inviteItems,
  39. 'url': inviteUrl
  40. }),
  41. resolve,
  42. 'json')
  43. .fail((jqxhr, textStatus, error) => reject(error));
  44. });
  45. }
  46. /**
  47. * Indicates if an invite option is enabled in the configuration.
  48. *
  49. * @param {string} name - The name of the option defined in
  50. * interfaceConfig.INVITE_OPTIONS.
  51. * @returns {boolean} - True to indicate that the given invite option is
  52. * enabled, false - otherwise.
  53. */
  54. export function isInviteOptionEnabled(name: string) {
  55. return getInviteOptionPosition(name) !== -1;
  56. }
  57. /**
  58. * Sends an ajax request to a directory service.
  59. *
  60. * @param {string} serviceUrl - The service to query.
  61. * @param {string} jwt - The jwt token to pass to the search service.
  62. * @param {string} text - Text to search.
  63. * @param {Array<string>} queryTypes - Array with the query types that will be
  64. * executed - "conferenceRooms" | "user" | "room".
  65. * @returns {Promise} - The promise created by the request.
  66. */
  67. export function searchDirectory( // eslint-disable-line max-params
  68. serviceUrl: string,
  69. jwt: string,
  70. text: string,
  71. queryTypes: Array<string> = [ 'conferenceRooms', 'user', 'room' ]) {
  72. const queryTypesString = JSON.stringify(queryTypes);
  73. return new Promise((resolve, reject) => {
  74. $.getJSON(
  75. `${serviceUrl}?query=${encodeURIComponent(text)}&queryTypes=${
  76. queryTypesString}&jwt=${jwt}`,
  77. resolve)
  78. .fail((jqxhr, textStatus, error) => reject(error));
  79. });
  80. }