Преглед на файлове

Coding style: naming, comments

master
Lyubo Marinov преди 7 години
родител
ревизия
5e8ecc5fee

+ 0
- 1
react/features/app/components/App.native.js Целия файл

@@ -6,7 +6,6 @@ import { Linking } from 'react-native';
6 6
 
7 7
 import '../../analytics';
8 8
 import '../../authentication';
9
-import '../../base/domains';
10 9
 import { Platform } from '../../base/react';
11 10
 import {
12 11
     AspectRatioDetector,

+ 0
- 21
react/features/base/domains/actions.js Целия файл

@@ -1,21 +0,0 @@
1
-// @flow
2
-
3
-import { ADD_KNOWN_DOMAINS } from './actionTypes';
4
-
5
-/**
6
- * Sends an action to add one or an array of known domains if not present yet.
7
- *
8
- * @param {string | Array<string>} knownDomains - The new domain as a string or
9
- * an array of domains.
10
- * @returns {{
11
- *     type: ADD_KNOWN_DOMAINS,
12
- *     knownDomains: Array<string>
13
- * }}
14
- */
15
-export function addKnownDomains(knownDomains: string | Array<string>) {
16
-    return {
17
-        type: ADD_KNOWN_DOMAINS,
18
-        knownDomains: typeof knownDomains === 'string'
19
-            ? [ knownDomains ] : knownDomains
20
-    };
21
-}

+ 0
- 15
react/features/base/domains/constants.js Целия файл

@@ -1,15 +0,0 @@
1
-// @flow
2
-
3
-/**
4
- * A list of domains we consider jitsi-enabled domains by default. This is in
5
- * line with the app links on iOS and Android, but stands here as retreiving
6
- * those programatically is not straightforward.
7
- */
8
-export const JITSI_KNOWN_DOMAINS = [
9
-    'beta.meet.jit.si',
10
-    'beta.hipchat.me',
11
-    'chaos.hipchat.me',
12
-    'enso.me',
13
-    'hipchat.me',
14
-    'meet.jit.si'
15
-];

+ 0
- 49
react/features/base/domains/reducer.js Целия файл

@@ -1,49 +0,0 @@
1
-// @flow
2
-
3
-import { ReducerRegistry } from '../redux';
4
-import { PersistenceRegistry } from '../storage';
5
-
6
-import { ADD_KNOWN_DOMAINS } from './actionTypes';
7
-
8
-const DEFAULT_STATE = [];
9
-
10
-const STORE_NAME = 'features/base/domains';
11
-
12
-PersistenceRegistry.register(STORE_NAME);
13
-
14
-ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
15
-    switch (action.type) {
16
-    case ADD_KNOWN_DOMAINS:
17
-        return _addKnownDomain(state, action);
18
-
19
-    default:
20
-        return state;
21
-    }
22
-});
23
-
24
-/**
25
- * Adds an array of new domains to the known domain list if not present yet.
26
- *
27
- * @param {Object} state - The redux state.
28
- * @param {Object} action - The redux action.
29
- * @private
30
- * @returns {Object}
31
- */
32
-function _addKnownDomain(state, action) {
33
-    const { knownDomains: knownDomainsToAdd } = action;
34
-    const knownDomains = Array.from(state);
35
-
36
-    if (Array.isArray(knownDomainsToAdd)) {
37
-        for (let knownDomain of knownDomainsToAdd) {
38
-            knownDomain = knownDomain.toLowerCase();
39
-
40
-            if (knownDomains.indexOf(knownDomain) === -1) {
41
-                knownDomains.push(knownDomain);
42
-            }
43
-        }
44
-
45
-        return knownDomains;
46
-    }
47
-
48
-    return state;
49
-}

react/features/base/domains/actionTypes.js → react/features/base/known-domains/actionTypes.js Целия файл

@@ -1,8 +1,8 @@
1 1
 // @flow
2 2
 
3 3
 /**
4
- * Action to add new domains to the list of domains known to the feature
5
- * base/domains.
4
+ * The type of (redux) action to add known domains to the list of domains known
5
+ * to the feature base/known-domains.
6 6
  *
7 7
  * {
8 8
  *     type: ADD_KNOWN_DOMAINS,

+ 22
- 0
react/features/base/known-domains/actions.js Целия файл

@@ -0,0 +1,22 @@
1
+// @flow
2
+
3
+import { ADD_KNOWN_DOMAINS } from './actionTypes';
4
+
5
+/**
6
+ * Creates a (redux) action to add known domains to the list of domains known to
7
+ * the feature base/known-domains.
8
+ *
9
+ * @param {string | Array<string>} knownDomains - The known domain(s) to add to
10
+ * the list of domains known to the feature base/known-domains.
11
+ * @returns {{
12
+ *     type: ADD_KNOWN_DOMAINS,
13
+ *     knownDomains: Array<string>
14
+ * }}
15
+ */
16
+export function addKnownDomains(knownDomains: string | Array<string>) {
17
+    return {
18
+        type: ADD_KNOWN_DOMAINS,
19
+        knownDomains:
20
+            typeof knownDomains === 'string' ? [ knownDomains ] : knownDomains
21
+    };
22
+}

react/features/base/domains/index.js → react/features/base/known-domains/index.js Целия файл


react/features/base/domains/middleware.js → react/features/base/known-domains/middleware.js Целия файл

@@ -6,19 +6,17 @@ import { MiddlewareRegistry } from '../redux';
6 6
 import { parseURIString } from '../util';
7 7
 
8 8
 import { addKnownDomains } from './actions';
9
-import { JITSI_KNOWN_DOMAINS } from './constants';
10 9
 
11 10
 MiddlewareRegistry.register(store => next => action => {
12 11
     const result = next(action);
13 12
 
14 13
     switch (action.type) {
15
-
16 14
     case APP_WILL_MOUNT:
17
-        _ensureDefaultServer(store);
15
+        _appWillMount(store);
18 16
         break;
19 17
 
20 18
     case SET_ROOM:
21
-        _parseAndAddKnownDomain(store);
19
+        _setRoom(store);
22 20
         break;
23 21
     }
24 22
 
@@ -26,34 +24,33 @@ MiddlewareRegistry.register(store => next => action => {
26 24
 });
27 25
 
28 26
 /**
29
- * Ensures presence of the default server in the known domains list.
27
+ * Adds the domain of the app's {@code defaultURL} to the list of domains known
28
+ * to the feature base/known-domains.
30 29
  *
31 30
  * @param {Object} store - The redux store.
32 31
  * @private
33 32
  * @returns {Promise}
34 33
  */
35
-function _ensureDefaultServer({ dispatch, getState }) {
36
-    const { app } = getState()['features/app'];
37
-    const defaultURL = parseURIString(app._getDefaultURL());
38
-
39
-    dispatch(addKnownDomains([
40
-        defaultURL.host,
41
-        ...JITSI_KNOWN_DOMAINS
42
-    ]));
34
+function _appWillMount({ dispatch, getState }) {
35
+    const defaultURL
36
+        = parseURIString(getState()['features/app'].app._getDefaultURL());
37
+
38
+    dispatch(addKnownDomains(defaultURL.host));
43 39
 }
44 40
 
45 41
 /**
46
- * Retrieves the domain name of a room upon join and stores it in the known
47
- * domain list, if not present yet.
42
+ * Adds the domain of {@code locationURL} to the list of domains known to the
43
+ * feature base/known-domains.
48 44
  *
49 45
  * @param {Object} store - The redux store.
50 46
  * @private
51 47
  * @returns {Promise}
52 48
  */
53
-function _parseAndAddKnownDomain({ dispatch, getState }) {
49
+function _setRoom({ dispatch, getState }) {
54 50
     const { locationURL } = getState()['features/base/connection'];
51
+    let host;
55 52
 
56 53
     locationURL
57
-        && locationURL.host
58
-        && dispatch(addKnownDomains(locationURL.host));
54
+        && (host = locationURL.host)
55
+        && dispatch(addKnownDomains(host));
59 56
 }

+ 70
- 0
react/features/base/known-domains/reducer.js Целия файл

@@ -0,0 +1,70 @@
1
+// @flow
2
+
3
+import { APP_WILL_MOUNT } from '../../app';
4
+import { ReducerRegistry } from '../redux';
5
+import { PersistenceRegistry } from '../storage';
6
+
7
+import { ADD_KNOWN_DOMAINS } from './actionTypes';
8
+
9
+/**
10
+ * The default list of domains known to the feature base/known-domains.
11
+ * Generally, it should be in sync with the domains associated with the app
12
+ * through its manifest (in other words, Universal Links, deep linking). Anyway,
13
+ * we need a hardcoded list because it has proven impossible to programmatically
14
+ * read the information out of the app's manifests: App Store strips the
15
+ * associated domains manifest out of the app so it's never downloaded on the
16
+ * client and we did not spend a lot of effort to read the associated domains
17
+ * out of the Andorid manifest.
18
+ */
19
+export const DEFAULT_STATE = [
20
+    'beta.hipchat.me',
21
+    'beta.meet.jit.si',
22
+    'chaos.hipchat.me',
23
+    'enso.me',
24
+    'hipchat.me',
25
+    'meet.jit.si'
26
+];
27
+
28
+const STORE_NAME = 'features/base/known-domains';
29
+
30
+PersistenceRegistry.register(STORE_NAME);
31
+
32
+ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
33
+    switch (action.type) {
34
+    case ADD_KNOWN_DOMAINS:
35
+        return _addKnownDomains(state, action.knownDomains);
36
+
37
+    case APP_WILL_MOUNT:
38
+        // In case persistence has deserialized a weird redux state:
39
+        return _addKnownDomains(state, DEFAULT_STATE);
40
+
41
+    default:
42
+        return state;
43
+    }
44
+});
45
+
46
+/**
47
+ * Adds an array of known domains to the list of domains known to the feature
48
+ * base/known-domains.
49
+ *
50
+ * @param {Object} state - The redux state.
51
+ * @param {Array<string>} knownDomains - The array of known domains to add to
52
+ * the list of domains known to the feature base/known-domains.
53
+ * @private
54
+ * @returns {Object} The next redux state.
55
+ */
56
+function _addKnownDomains(state, knownDomains) {
57
+    // In case persistence has deserialized a weird redux state:
58
+    let nextState = Array.isArray(state) ? state : [];
59
+
60
+    if (Array.isArray(knownDomains)) {
61
+        nextState = Array.from(state);
62
+        for (let knownDomain of knownDomains) {
63
+            knownDomain = knownDomain.toLowerCase();
64
+            nextState.indexOf(knownDomain) === -1
65
+                && nextState.push(knownDomain);
66
+        }
67
+    }
68
+
69
+    return nextState;
70
+}

+ 43
- 47
react/features/calendar-sync/middleware.js Целия файл

@@ -3,27 +3,24 @@
3 3
 import RNCalendarEvents from 'react-native-calendar-events';
4 4
 
5 5
 import { APP_WILL_MOUNT } from '../app';
6
-import { ADD_KNOWN_DOMAINS } from '../base/domains';
6
+import { ADD_KNOWN_DOMAINS } from '../base/known-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
-import {
12
-    setCalendarAuthorization,
13
-    setCalendarEvents
14
-} from './actions';
11
+import { setCalendarAuthorization, setCalendarEvents } from './actions';
15 12
 import { REFRESH_CALENDAR } from './actionTypes';
16 13
 import { CALENDAR_ENABLED } from './constants';
17 14
 
18 15
 const logger = require('jitsi-meet-logger').getLogger(__filename);
19 16
 
20 17
 /**
21
- * The no. of days to fetch.
18
+ * The number of days to fetch.
22 19
  */
23 20
 const FETCH_END_DAYS = 10;
24 21
 
25 22
 /**
26
- * The no. of days to go back when fetching.
23
+ * The number of days to go back when fetching.
27 24
  */
28 25
 const FETCH_START_DAYS = -1;
29 26
 
@@ -37,15 +34,15 @@ CALENDAR_ENABLED
37 34
         const result = next(action);
38 35
 
39 36
         switch (action.type) {
40
-        case APP_STATE_CHANGED:
41
-            _maybeClearAccessStatus(store, action);
42
-            break;
43
-
44 37
         case ADD_KNOWN_DOMAINS:
45 38
         case APP_WILL_MOUNT:
46 39
             _fetchCalendarEntries(store, false, false);
47 40
             break;
48 41
 
42
+        case APP_STATE_CHANGED:
43
+            _maybeClearAccessStatus(store, action);
44
+            break;
45
+
49 46
         case REFRESH_CALENDAR:
50 47
             _fetchCalendarEntries(store, true, action.forcePermission);
51 48
             break;
@@ -54,23 +51,6 @@ CALENDAR_ENABLED
54 51
         return result;
55 52
     });
56 53
 
57
-/**
58
- * Clears the calendar access status when the app comes back from the
59
- * background. This is needed as some users may never quit the app, but puts it
60
- * into the background and we need to try to request for a permission as often
61
- * as possible, but not annoyingly often.
62
- *
63
- * @param {Object} store - The redux store.
64
- * @param {Object} action - The Redux action.
65
- * @private
66
- * @returns {void}
67
- */
68
-function _maybeClearAccessStatus(store, { appState }) {
69
-    if (appState === 'background') {
70
-        store.dispatch(setCalendarAuthorization(undefined));
71
-    }
72
-}
73
-
74 54
 /**
75 55
  * Ensures calendar access if possible and resolves the promise if it's granted.
76 56
  *
@@ -113,13 +93,13 @@ function _ensureCalendarAccess(promptForPermission, dispatch) {
113 93
  * @returns {void}
114 94
  */
115 95
 function _fetchCalendarEntries(
116
-        { dispatch, getState },
96
+        store,
117 97
         maybePromptForPermission,
118 98
         forcePermission) {
119
-    const featureState = getState()['features/calendar-sync'];
120
-    const knownDomains = getState()['features/base/domains'];
99
+    const { dispatch, getState } = store;
121 100
     const promptForPermission
122
-        = (maybePromptForPermission && !featureState.authorization)
101
+        = (maybePromptForPermission
102
+                && !getState()['features/calendar-sync'].authorization)
123 103
             || forcePermission;
124 104
 
125 105
     _ensureCalendarAccess(promptForPermission, dispatch)
@@ -135,11 +115,7 @@ function _fetchCalendarEntries(
135 115
                         startDate.getTime(),
136 116
                         endDate.getTime(),
137 117
                         [])
138
-                    .then(events =>
139
-                        _updateCalendarEntries(
140
-                            events,
141
-                            knownDomains,
142
-                            dispatch))
118
+                    .then(_updateCalendarEntries.bind(store))
143 119
                     .catch(error =>
144 120
                         logger.error('Error fetching calendar.', error));
145 121
             } else {
@@ -192,6 +168,22 @@ function _getURLFromEvent(event, knownDomains) {
192 168
     return null;
193 169
 }
194 170
 
171
+/**
172
+ * Clears the calendar access status when the app comes back from the
173
+ * background. This is needed as some users may never quit the app, but puts it
174
+ * into the background and we need to try to request for a permission as often
175
+ * as possible, but not annoyingly often.
176
+ *
177
+ * @param {Object} store - The redux store.
178
+ * @param {Object} action - The Redux action.
179
+ * @private
180
+ * @returns {void}
181
+ */
182
+function _maybeClearAccessStatus(store, { appState }) {
183
+    appState === 'background'
184
+        && store.dispatch(setCalendarAuthorization(undefined));
185
+}
186
+
195 187
 /**
196 188
  * Updates the calendar entries in Redux when new list is received.
197 189
  *
@@ -231,26 +223,30 @@ function _parseCalendarEntry(event, knownDomains) {
231 223
 }
232 224
 
233 225
 /**
234
- * Updates the calendar entries in Redux when new list is received.
226
+ * Updates the calendar entries in redux when new list is received.
227
+ *
228
+ * XXX The function's {@code this} is the redux store.
235 229
  *
236 230
  * @param {Array<CalendarEntry>} events - The new event list.
237
- * @param {Array<string>} knownDomains - The known domain list.
238
- * @param {Function} dispatch - The Redux dispatch function.
239 231
  * @private
240 232
  * @returns {void}
241 233
  */
242
-function _updateCalendarEntries(events, knownDomains, dispatch) {
234
+function _updateCalendarEntries(events) {
243 235
     if (events && events.length) {
236
+        // eslint-disable-next-line no-invalid-this
237
+        const { dispatch, getState } = this;
238
+
239
+        const knownDomains = getState()['features/base/known-domains'];
244 240
         const eventList = [];
245 241
 
242
+        const now = Date.now();
243
+
246 244
         for (const event of events) {
247
-            const calendarEntry
248
-                = _parseCalendarEntry(event, knownDomains);
249
-            const now = Date.now();
245
+            const calendarEntry = _parseCalendarEntry(event, knownDomains);
250 246
 
251
-            if (calendarEntry && calendarEntry.endDate > now) {
252
-                eventList.push(calendarEntry);
253
-            }
247
+            calendarEntry
248
+                && calendarEntry.endDate > now
249
+                && eventList.push(calendarEntry);
254 250
         }
255 251
 
256 252
         dispatch(

Loading…
Отказ
Запис