Browse Source

[RN] If calendar-sync knows a domain, then the app knows it

master
Zoltan Bettenbuk 7 years ago
parent
commit
46bc63b79e

+ 0
- 11
react/features/calendar-sync/actionTypes.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-/**
4
- * Action to add a new domain to the list of domain known to the feature
5
- * calendar-sync.
6
- *
7
- * {
8
- *     type: ADD_KNOWN_DOMAIN,
9
- *     knownDomain: string
10
- * }
11
- */
12
-export const ADD_KNOWN_DOMAIN = Symbol('ADD_KNOWN_DOMAIN');
13
-
14
 /**
3
 /**
15
  * Action to refresh (re-fetch) the entry list.
4
  * Action to refresh (re-fetch) the entry list.
16
  *
5
  *

+ 0
- 17
react/features/calendar-sync/actions.js View File

3
 import {
3
 import {
4
     SET_CALENDAR_AUTHORIZATION,
4
     SET_CALENDAR_AUTHORIZATION,
5
     SET_CALENDAR_EVENTS,
5
     SET_CALENDAR_EVENTS,
6
-    ADD_KNOWN_DOMAIN,
7
     REFRESH_CALENDAR
6
     REFRESH_CALENDAR
8
 } from './actionTypes';
7
 } from './actionTypes';
9
 
8
 
10
-/**
11
- * Sends an action to add a new known domain if not present yet.
12
- *
13
- * @param {string} knownDomain - The new domain.
14
- * @returns {{
15
- *     type: ADD_KNOWN_DOMAIN,
16
- *     knownDomain: string
17
- * }}
18
- */
19
-export function addKnownDomain(knownDomain: string) {
20
-    return {
21
-        type: ADD_KNOWN_DOMAIN,
22
-        knownDomain
23
-    };
24
-}
25
-
26
 /**
9
 /**
27
  * Sends an action to refresh the entry list (fetches new data).
10
  * Sends an action to refresh the entry list (fetches new data).
28
  *
11
  *

+ 17
- 38
react/features/calendar-sync/middleware.js View File

3
 import RNCalendarEvents from 'react-native-calendar-events';
3
 import RNCalendarEvents from 'react-native-calendar-events';
4
 
4
 
5
 import { APP_WILL_MOUNT } from '../app';
5
 import { APP_WILL_MOUNT } from '../app';
6
-import { SET_ROOM } from '../base/conference';
6
+import { ADD_KNOWN_DOMAINS } from '../base/domains';
7
 import { MiddlewareRegistry } from '../base/redux';
7
 import { MiddlewareRegistry } from '../base/redux';
8
 import { APP_LINK_SCHEME, parseURIString } from '../base/util';
8
 import { APP_LINK_SCHEME, parseURIString } from '../base/util';
9
 import { APP_STATE_CHANGED } from '../mobile/background';
9
 import { APP_STATE_CHANGED } from '../mobile/background';
10
 
10
 
11
 import {
11
 import {
12
-    addKnownDomain,
13
     setCalendarAuthorization,
12
     setCalendarAuthorization,
14
     setCalendarEvents
13
     setCalendarEvents
15
 } from './actions';
14
 } from './actions';
18
 
17
 
19
 const logger = require('jitsi-meet-logger').getLogger(__filename);
18
 const logger = require('jitsi-meet-logger').getLogger(__filename);
20
 
19
 
20
+/**
21
+ * The no. of days to fetch.
22
+ */
21
 const FETCH_END_DAYS = 10;
23
 const FETCH_END_DAYS = 10;
24
+
25
+/**
26
+ * The no. of days to go back when fetching.
27
+ */
22
 const FETCH_START_DAYS = -1;
28
 const FETCH_START_DAYS = -1;
29
+
30
+/**
31
+ * The max number of events to fetch from the calendar.
32
+ */
23
 const MAX_LIST_LENGTH = 10;
33
 const MAX_LIST_LENGTH = 10;
24
 
34
 
25
 CALENDAR_ENABLED
35
 CALENDAR_ENABLED
31
             _maybeClearAccessStatus(store, action);
41
             _maybeClearAccessStatus(store, action);
32
             break;
42
             break;
33
 
43
 
44
+        case ADD_KNOWN_DOMAINS:
34
         case APP_WILL_MOUNT:
45
         case APP_WILL_MOUNT:
35
-            _ensureDefaultServer(store);
36
             _fetchCalendarEntries(store, false, false);
46
             _fetchCalendarEntries(store, false, false);
37
             break;
47
             break;
38
 
48
 
39
         case REFRESH_CALENDAR:
49
         case REFRESH_CALENDAR:
40
             _fetchCalendarEntries(store, true, action.forcePermission);
50
             _fetchCalendarEntries(store, true, action.forcePermission);
41
             break;
51
             break;
42
-
43
-        case SET_ROOM:
44
-            _parseAndAddKnownDomain(store);
45
-            break;
46
         }
52
         }
47
 
53
 
48
         return result;
54
         return result;
95
     });
101
     });
96
 }
102
 }
97
 
103
 
98
-/**
99
- * Ensures presence of the default server in the known domains list.
100
- *
101
- * @param {Object} store - The redux store.
102
- * @private
103
- * @returns {Promise}
104
- */
105
-function _ensureDefaultServer({ dispatch, getState }) {
106
-    const defaultURL
107
-        = parseURIString(getState()['features/app'].app._getDefaultURL());
108
-
109
-    dispatch(addKnownDomain(defaultURL.host));
110
-}
111
-
112
 /**
104
 /**
113
  * Reads the user's calendar and updates the stored entries if need be.
105
  * Reads the user's calendar and updates the stored entries if need be.
114
  *
106
  *
124
         { dispatch, getState },
116
         { dispatch, getState },
125
         maybePromptForPermission,
117
         maybePromptForPermission,
126
         forcePermission) {
118
         forcePermission) {
127
-    const state = getState()['features/calendar-sync'];
119
+    const featureState = getState()['features/calendar-sync'];
120
+    const knownDomains = getState()['features/base/domains'];
128
     const promptForPermission
121
     const promptForPermission
129
-        = (maybePromptForPermission && !state.authorization)
122
+        = (maybePromptForPermission && !featureState.authorization)
130
             || forcePermission;
123
             || forcePermission;
131
 
124
 
132
     _ensureCalendarAccess(promptForPermission, dispatch)
125
     _ensureCalendarAccess(promptForPermission, dispatch)
145
                     .then(events =>
138
                     .then(events =>
146
                         _updateCalendarEntries(
139
                         _updateCalendarEntries(
147
                             events,
140
                             events,
148
-                            state.knownDomains,
141
+                            knownDomains,
149
                             dispatch))
142
                             dispatch))
150
                     .catch(error =>
143
                     .catch(error =>
151
                         logger.error('Error fetching calendar.', error));
144
                         logger.error('Error fetching calendar.', error));
199
     return null;
192
     return null;
200
 }
193
 }
201
 
194
 
202
-/**
203
- * Retrieves the domain name of a room upon join and stores it in the known
204
- * domain list, if not present yet.
205
- *
206
- * @param {Object} store - The redux store.
207
- * @private
208
- * @returns {Promise}
209
- */
210
-function _parseAndAddKnownDomain({ dispatch, getState }) {
211
-    const { locationURL } = getState()['features/base/connection'];
212
-
213
-    dispatch(addKnownDomain(locationURL.host));
214
-}
215
-
216
 /**
195
 /**
217
  * Updates the calendar entries in Redux when new list is received.
196
  * Updates the calendar entries in Redux when new list is received.
218
  *
197
  *

+ 1
- 51
react/features/calendar-sync/reducer.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import { ReducerRegistry } from '../base/redux';
3
 import { ReducerRegistry } from '../base/redux';
4
-import { PersistenceRegistry } from '../base/storage';
5
 
4
 
6
 import {
5
 import {
7
-    ADD_KNOWN_DOMAIN,
8
     SET_CALENDAR_AUTHORIZATION,
6
     SET_CALENDAR_AUTHORIZATION,
9
     SET_CALENDAR_EVENTS
7
     SET_CALENDAR_EVENTS
10
 } from './actionTypes';
8
 } from './actionTypes';
17
      * need to re-request the calendar permission from the user.
15
      * need to re-request the calendar permission from the user.
18
      */
16
      */
19
     authorization: undefined,
17
     authorization: undefined,
20
-    events: [],
21
-    knownDomains: []
18
+    events: []
22
 };
19
 };
23
 
20
 
24
-const MAX_DOMAIN_LIST_SIZE = 10;
25
-
26
 const STORE_NAME = 'features/calendar-sync';
21
 const STORE_NAME = 'features/calendar-sync';
27
 
22
 
28
-CALENDAR_ENABLED
29
-    && PersistenceRegistry.register(STORE_NAME, {
30
-        knownDomains: true
31
-    });
32
-
33
 CALENDAR_ENABLED
23
 CALENDAR_ENABLED
34
     && ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
24
     && ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
35
         switch (action.type) {
25
         switch (action.type) {
36
-        case ADD_KNOWN_DOMAIN:
37
-            return _addKnownDomain(state, action);
38
 
26
 
39
         case SET_CALENDAR_AUTHORIZATION:
27
         case SET_CALENDAR_AUTHORIZATION:
40
             return {
28
             return {
52
             return state;
40
             return state;
53
         }
41
         }
54
     });
42
     });
55
-
56
-/**
57
- * Adds a new domain to the known domain list if not present yet.
58
- *
59
- * @param {Object} state - The redux state.
60
- * @param {Object} action - The redux action.
61
- * @private
62
- * @returns {Object}
63
- */
64
-function _addKnownDomain(state, action) {
65
-    let { knownDomain } = action;
66
-
67
-    if (knownDomain) {
68
-        knownDomain = knownDomain.toLowerCase();
69
-
70
-        let { knownDomains } = state;
71
-
72
-        if (knownDomains.indexOf(knownDomain) === -1) {
73
-            // Add the specified known domain and at the same time avoid
74
-            // modifying the knownDomains Array instance referenced by the
75
-            // current redux state.
76
-            knownDomains = [
77
-                ...state.knownDomains,
78
-                knownDomain
79
-            ];
80
-
81
-            // Ensure the list doesn't exceed a/the maximum size.
82
-            knownDomains.splice(0, knownDomains.length - MAX_DOMAIN_LIST_SIZE);
83
-
84
-            return {
85
-                ...state,
86
-                knownDomains
87
-            };
88
-        }
89
-    }
90
-
91
-    return state;
92
-}

Loading…
Cancel
Save