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.web.js 2.8KB

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