您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.web.js 3.2KB

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