Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

[RN] Legacy support of calendar-sync's knownDomains

Lyubo Marinov631f51d6277b
diff --git a/react/features/calendar-sync/middleware.js b/react/features/calendar-sync/middleware.js
index 1407cd10da..0a0c7210c6 100644
--- a/react/features/calendar-sync/middleware.js
+++ b/react/features/calendar-sync/middleware.js
@@ -3,7 +3,7 @@
import RNCalendarEvents from 'react-native-calendar-events';
import { APP_WILL_MOUNT } from '../app';
-import { ADD_KNOWN_DOMAINS } from '../base/known-domains';
+import { ADD_KNOWN_DOMAINS, addKnownDomains } from '../base/known-domains';
import { MiddlewareRegistry } from '../base/redux';
import { APP_LINK_SCHEME, parseURIString } from '../base/util';
import { APP_STATE_CHANGED } from '../mobile/background';
@@ -31,24 +31,58 @@ const MAX_LIST_LENGTH = 10;
CALENDAR_ENABLED
&& MiddlewareRegistry.register(store => next => action => {
- const result = next(action);
-
switch (action.type) {
- case ADD_KNOWN_DOMAINS:
- case APP_WILL_MOUNT:
- _fetchCalendarEntries(store, false, false);
- break;
+ case ADD_KNOWN_DOMAINS: {
+ // XXX Fetch new calendar entries only when an actual domain has
+ // become known.
+ const { getState } = store;
+ const oldValue = getState()['features/base/known-domains'];
+ const result = next(action);
+ const newValue = getState()['features/base/known-domains'];
+
+ oldValue === newValue || _fetchCalendarEntries(store, false, false);
+
+ return result;
+ }
+
+ case APP_STATE_CHANGED: {
+ const result = next(action);
- case APP_STATE_CHANGED:
_maybeClearAccessStatus(store, action);
- break;
- case REFRESH_CALENDAR:
+ return result;
+ }
+
+ case APP_WILL_MOUNT: {
+ // For legacy purposes, we've allowed the deserialization of
+ // knownDomains and now we're to translate it to base/known-domains.
+ const state = store.getState()['features/calendar-sync'];
+
+ if (state) {
+ const { knownDomains } = state;
+
+ Array.isArray(knownDomains)
+ && knownDomains.length
+ && store.dispatch(addKnownDomains(knownDomains));
+ }
+
+ const result = next(action);
+
+ _fetchCalendarEntries(store, false, false);
+
+ return result;
+ }
+
+ case REFRESH_CALENDAR: {
+ const result = next(action);
+
_fetchCalendarEntries(store, true, action.forcePermission);
- break;
+
+ return result;
+ }
}
- return result;
+ return next(action);
});
/**
@@ -122,9 +156,7 @@ function _fetchCalendarEntries(
logger.warn('Calendar access not granted.');
}
})
- .catch(reason => {
- logger.error('Error accessing calendar.', reason);
- });
+ .catch(reason => logger.error('Error accessing calendar.', reason));
}
/**
diff --git a/react/features/calendar-sync/reducer.js b/react/features/calendar-sync/reducer.js
index 00c348f894..7a302dd313 100644
--- a/react/features/calendar-sync/reducer.js
+++ b/react/features/calendar-sync/reducer.js
@@ -1,6 +1,8 @@
// @flow
-import { ReducerRegistry } from '../base/redux';
+import { APP_WILL_MOUNT } from '../app';
+import { ReducerRegistry, set } from '../base/redux';
+import { PersistenceRegistry } from '../base/storage';
import {
SET_CALENDAR_AUTHORIZATION,
@@ -20,9 +22,25 @@ const DEFAULT_STATE = {
const STORE_NAME = 'features/calendar-sync';
+// XXX For legacy purposes, read any {@code knownDomains} persisted by the
+// feature calendar-sync.
+CALENDAR_ENABLED
+ && PersistenceRegistry.register(STORE_NAME, {
+ knownDomains: true
+ });
+
CALENDAR_ENABLED
&& ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
switch (action.type) {
+ case APP_WILL_MOUNT:
+ // For legacy purposes, we've allowed the deserialization of
+ // knownDomains. At this point, it should have already been
+ // translated into the new state format (namely, base/known-domains)
+ // and the app no longer needs it.
+ if (typeof state.knownDomains !== 'undefined') {
+ return set(state, 'knownDomains', undefined);
+ }
+ break;
case SET_CALENDAR_AUTHORIZATION:
return {
@@ -35,8 +53,7 @@ CALENDAR_ENABLED
...state,
events: action.events
};
-
- default:
- return state;
}
+
+ return state;
});