Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

functions.web.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // @flow
  2. export * from './functions.any';
  3. import {
  4. CALENDAR_TYPE,
  5. FETCH_END_DAYS,
  6. FETCH_START_DAYS
  7. } from './constants';
  8. import { _updateCalendarEntries } from './functions';
  9. import { googleCalendarApi } from './web/googleCalendar';
  10. import { microsoftCalendarApi } from './web/microsoftCalendar';
  11. const logger = require('jitsi-meet-logger').getLogger(__filename);
  12. declare var config: Object;
  13. /**
  14. * Determines whether the calendar feature is enabled by the web.
  15. *
  16. * @returns {boolean} If the app has enabled the calendar feature, {@code true};
  17. * otherwise, {@code false}.
  18. */
  19. export function isCalendarEnabled() {
  20. return Boolean(
  21. config.enableCalendarIntegration
  22. && (config.googleApiApplicationClientID
  23. || config.microsoftApiApplicationClientID));
  24. }
  25. /* eslint-disable no-unused-vars */
  26. /**
  27. * Reads the user's calendar and updates the stored entries if need be.
  28. *
  29. * @param {Object} store - The redux store.
  30. * @param {boolean} maybePromptForPermission - Flag to tell the app if it should
  31. * prompt for a calendar permission if it wasn't granted yet.
  32. * @param {boolean|undefined} forcePermission - Whether to force to re-ask for
  33. * the permission or not.
  34. * @private
  35. * @returns {void}
  36. */
  37. export function _fetchCalendarEntries(
  38. store,
  39. maybePromptForPermission,
  40. forcePermission) {
  41. /* eslint-enable no-unused-vars */
  42. const { dispatch, getState } = store;
  43. const { integrationType } = getState()['features/calendar-sync'];
  44. const integration = _getCalendarIntegration(integrationType);
  45. if (!integration) {
  46. logger.debug('No calendar type available');
  47. return;
  48. }
  49. dispatch(integration.load())
  50. .then(() => dispatch(integration._isSignedIn()))
  51. .then(signedIn => {
  52. if (signedIn) {
  53. return Promise.resolve();
  54. }
  55. return Promise.reject('Not authorized, please sign in!');
  56. })
  57. .then(() => dispatch(integration.getCalendarEntries(
  58. FETCH_START_DAYS, FETCH_END_DAYS)))
  59. .then(events => _updateCalendarEntries.call({
  60. dispatch,
  61. getState
  62. }, events))
  63. .catch(error =>
  64. logger.error('Error fetching calendar.', error));
  65. }
  66. /**
  67. * Returns the calendar API implementation by specified type.
  68. *
  69. * @param {string} calendarType - The calendar type API as defined in
  70. * the constant {@link CALENDAR_TYPE}.
  71. * @private
  72. * @returns {Object|undefined}
  73. */
  74. export function _getCalendarIntegration(calendarType: string) {
  75. switch (calendarType) {
  76. case CALENDAR_TYPE.GOOGLE:
  77. return googleCalendarApi;
  78. case CALENDAR_TYPE.MICROSOFT:
  79. return microsoftCalendarApi;
  80. }
  81. }