Переглянути джерело

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

master
Zoltan Bettenbuk 7 роки тому
джерело
коміт
46bc63b79e

+ 0
- 11
react/features/calendar-sync/actionTypes.js Переглянути файл

@@ -1,16 +1,5 @@
1 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 4
  * Action to refresh (re-fetch) the entry list.
16 5
  *

+ 0
- 17
react/features/calendar-sync/actions.js Переглянути файл

@@ -3,26 +3,9 @@
3 3
 import {
4 4
     SET_CALENDAR_AUTHORIZATION,
5 5
     SET_CALENDAR_EVENTS,
6
-    ADD_KNOWN_DOMAIN,
7 6
     REFRESH_CALENDAR
8 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 10
  * Sends an action to refresh the entry list (fetches new data).
28 11
  *

+ 17
- 38
react/features/calendar-sync/middleware.js Переглянути файл

@@ -3,13 +3,12 @@
3 3
 import RNCalendarEvents from 'react-native-calendar-events';
4 4
 
5 5
 import { APP_WILL_MOUNT } from '../app';
6
-import { SET_ROOM } from '../base/conference';
6
+import { ADD_KNOWN_DOMAINS } from '../base/domains';
7 7
 import { MiddlewareRegistry } from '../base/redux';
8 8
 import { APP_LINK_SCHEME, parseURIString } from '../base/util';
9 9
 import { APP_STATE_CHANGED } from '../mobile/background';
10 10
 
11 11
 import {
12
-    addKnownDomain,
13 12
     setCalendarAuthorization,
14 13
     setCalendarEvents
15 14
 } from './actions';
@@ -18,8 +17,19 @@ import { CALENDAR_ENABLED } from './constants';
18 17
 
19 18
 const logger = require('jitsi-meet-logger').getLogger(__filename);
20 19
 
20
+/**
21
+ * The no. of days to fetch.
22
+ */
21 23
 const FETCH_END_DAYS = 10;
24
+
25
+/**
26
+ * The no. of days to go back when fetching.
27
+ */
22 28
 const FETCH_START_DAYS = -1;
29
+
30
+/**
31
+ * The max number of events to fetch from the calendar.
32
+ */
23 33
 const MAX_LIST_LENGTH = 10;
24 34
 
25 35
 CALENDAR_ENABLED
@@ -31,18 +41,14 @@ CALENDAR_ENABLED
31 41
             _maybeClearAccessStatus(store, action);
32 42
             break;
33 43
 
44
+        case ADD_KNOWN_DOMAINS:
34 45
         case APP_WILL_MOUNT:
35
-            _ensureDefaultServer(store);
36 46
             _fetchCalendarEntries(store, false, false);
37 47
             break;
38 48
 
39 49
         case REFRESH_CALENDAR:
40 50
             _fetchCalendarEntries(store, true, action.forcePermission);
41 51
             break;
42
-
43
-        case SET_ROOM:
44
-            _parseAndAddKnownDomain(store);
45
-            break;
46 52
         }
47 53
 
48 54
         return result;
@@ -95,20 +101,6 @@ function _ensureCalendarAccess(promptForPermission, dispatch) {
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 105
  * Reads the user's calendar and updates the stored entries if need be.
114 106
  *
@@ -124,9 +116,10 @@ function _fetchCalendarEntries(
124 116
         { dispatch, getState },
125 117
         maybePromptForPermission,
126 118
         forcePermission) {
127
-    const state = getState()['features/calendar-sync'];
119
+    const featureState = getState()['features/calendar-sync'];
120
+    const knownDomains = getState()['features/base/domains'];
128 121
     const promptForPermission
129
-        = (maybePromptForPermission && !state.authorization)
122
+        = (maybePromptForPermission && !featureState.authorization)
130 123
             || forcePermission;
131 124
 
132 125
     _ensureCalendarAccess(promptForPermission, dispatch)
@@ -145,7 +138,7 @@ function _fetchCalendarEntries(
145 138
                     .then(events =>
146 139
                         _updateCalendarEntries(
147 140
                             events,
148
-                            state.knownDomains,
141
+                            knownDomains,
149 142
                             dispatch))
150 143
                     .catch(error =>
151 144
                         logger.error('Error fetching calendar.', error));
@@ -199,20 +192,6 @@ function _getURLFromEvent(event, knownDomains) {
199 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 196
  * Updates the calendar entries in Redux when new list is received.
218 197
  *

+ 1
- 51
react/features/calendar-sync/reducer.js Переглянути файл

@@ -1,10 +1,8 @@
1 1
 // @flow
2 2
 
3 3
 import { ReducerRegistry } from '../base/redux';
4
-import { PersistenceRegistry } from '../base/storage';
5 4
 
6 5
 import {
7
-    ADD_KNOWN_DOMAIN,
8 6
     SET_CALENDAR_AUTHORIZATION,
9 7
     SET_CALENDAR_EVENTS
10 8
 } from './actionTypes';
@@ -17,24 +15,14 @@ const DEFAULT_STATE = {
17 15
      * need to re-request the calendar permission from the user.
18 16
      */
19 17
     authorization: undefined,
20
-    events: [],
21
-    knownDomains: []
18
+    events: []
22 19
 };
23 20
 
24
-const MAX_DOMAIN_LIST_SIZE = 10;
25
-
26 21
 const STORE_NAME = 'features/calendar-sync';
27 22
 
28
-CALENDAR_ENABLED
29
-    && PersistenceRegistry.register(STORE_NAME, {
30
-        knownDomains: true
31
-    });
32
-
33 23
 CALENDAR_ENABLED
34 24
     && ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
35 25
         switch (action.type) {
36
-        case ADD_KNOWN_DOMAIN:
37
-            return _addKnownDomain(state, action);
38 26
 
39 27
         case SET_CALENDAR_AUTHORIZATION:
40 28
             return {
@@ -52,41 +40,3 @@ CALENDAR_ENABLED
52 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
-}

Завантаження…
Відмінити
Зберегти