Browse Source

[RN] If recent-list knows a domain, then the app knows it

master
Lyubo Marinov 7 years ago
parent
commit
d4dea22576

+ 17
- 2
react/features/recent-list/actionTypes.js View File

@@ -2,10 +2,25 @@
2 2
 
3 3
 /**
4 4
  * Action type to signal a new addition to the list.
5
+ *
6
+ * {
7
+ *     type: _STORE_CURRENT_CONFERENCE,
8
+ *     locationURL: Object
9
+ * }
10
+ *
11
+ * @protected
5 12
  */
6
-export const STORE_CURRENT_CONFERENCE = Symbol('STORE_CURRENT_CONFERENCE');
13
+export const _STORE_CURRENT_CONFERENCE = Symbol('_STORE_CURRENT_CONFERENCE');
7 14
 
8 15
 /**
9 16
  * Action type to signal that a new conference duration info is available.
17
+ *
18
+ * {
19
+ *     type: _UPDATE_CONFERENCE_DURATION,
20
+ *     locationURL: Object
21
+ * }
22
+ *
23
+ * @protected
10 24
  */
11
-export const UPDATE_CONFERENCE_DURATION = Symbol('UPDATE_CONFERENCE_DURATION');
25
+export const _UPDATE_CONFERENCE_DURATION
26
+    = Symbol('_UPDATE_CONFERENCE_DURATION');

+ 10
- 8
react/features/recent-list/actions.js View File

@@ -1,22 +1,23 @@
1 1
 // @flow
2 2
 
3 3
 import {
4
-    STORE_CURRENT_CONFERENCE,
5
-    UPDATE_CONFERENCE_DURATION
4
+    _STORE_CURRENT_CONFERENCE,
5
+    _UPDATE_CONFERENCE_DURATION
6 6
 } from './actionTypes';
7 7
 
8 8
 /**
9 9
  * Action to initiate a new addition to the list.
10 10
  *
11 11
  * @param {Object} locationURL - The current location URL.
12
+ * @protected
12 13
  * @returns {{
13
- *     type: STORE_CURRENT_CONFERENCE,
14
+ *     type: _STORE_CURRENT_CONFERENCE,
14 15
  *     locationURL: Object
15 16
  * }}
16 17
  */
17
-export function storeCurrentConference(locationURL: Object) {
18
+export function _storeCurrentConference(locationURL: Object) {
18 19
     return {
19
-        type: STORE_CURRENT_CONFERENCE,
20
+        type: _STORE_CURRENT_CONFERENCE,
20 21
         locationURL
21 22
     };
22 23
 }
@@ -25,14 +26,15 @@ export function storeCurrentConference(locationURL: Object) {
25 26
  * Action to initiate the update of the duration of the last conference.
26 27
  *
27 28
  * @param {Object} locationURL - The current location URL.
29
+ * @protected
28 30
  * @returns {{
29
- *     type: UPDATE_CONFERENCE_DURATION,
31
+ *     type: _UPDATE_CONFERENCE_DURATION,
30 32
  *     locationURL: Object
31 33
  * }}
32 34
  */
33
-export function updateConferenceDuration(locationURL: Object) {
35
+export function _updateConferenceDuration(locationURL: Object) {
34 36
     return {
35
-        type: UPDATE_CONFERENCE_DURATION,
37
+        type: _UPDATE_CONFERENCE_DURATION,
36 38
         locationURL
37 39
     };
38 40
 }

+ 76
- 19
react/features/recent-list/middleware.js View File

@@ -1,9 +1,12 @@
1 1
 // @flow
2 2
 
3
+import { APP_WILL_MOUNT } from '../app';
3 4
 import { CONFERENCE_WILL_LEAVE, SET_ROOM } from '../base/conference';
5
+import { addKnownDomains } from '../base/known-domains';
4 6
 import { MiddlewareRegistry } from '../base/redux';
7
+import { parseURIString } from '../base/util';
5 8
 
6
-import { storeCurrentConference, updateConferenceDuration } from './actions';
9
+import { _storeCurrentConference, _updateConferenceDuration } from './actions';
7 10
 
8 11
 /**
9 12
  * Middleware that captures joined rooms so they can be saved into
@@ -14,45 +17,99 @@ import { storeCurrentConference, updateConferenceDuration } from './actions';
14 17
  */
15 18
 MiddlewareRegistry.register(store => next => action => {
16 19
     switch (action.type) {
20
+    case APP_WILL_MOUNT:
21
+        return _appWillMount(store, next, action);
22
+
17 23
     case CONFERENCE_WILL_LEAVE:
18
-        _updateConferenceDuration(store);
19
-        break;
24
+        return _conferenceWillLeave(store, next, action);
20 25
 
21 26
     case SET_ROOM:
22
-        _maybeStoreCurrentConference(store, action);
23
-        break;
27
+        return _setRoom(store, next, action);
24 28
     }
25 29
 
26 30
     return next(action);
27 31
 });
28 32
 
29 33
 /**
30
- * Checks if there is a current conference (upon SET_ROOM action), and saves it
31
- * if necessary.
34
+ * Notifies the feature recent-list that the redux action {@link APP_WILL_MOUNT}
35
+ * is being dispatched in a specific redux store.
32 36
  *
33
- * @param {Store} store - The redux store.
34
- * @param {Dispatch} next - The redux {@code dispatch} function.
35
- * @param {Action} action - The redux action.
37
+ * @param {Store} store - The redux store in which the specified action is being
38
+ * dispatched.
39
+ * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
40
+ * specified action to the specified store.
41
+ * @param {Action} action - The redux action {@code APP_WILL_MOUNT} which is
42
+ * being dispatched in the specified redux store.
36 43
  * @private
37
- * @returns {void}
44
+ * @returns {*} The result returned by {@code next(action)}.
38 45
  */
39
-function _maybeStoreCurrentConference({ dispatch, getState }, { room }) {
40
-    if (room) {
41
-        const { locationURL } = getState()['features/base/connection'];
46
+function _appWillMount({ dispatch, getState }, next, action) {
47
+    const result = next(action);
48
+
49
+    // It's an opportune time to transfer the feature recent-list's knowledge
50
+    // about "known domains" (which is local to the feature) to the feature
51
+    // base/known-domains (which is global to the app).
52
+    //
53
+    // XXX Since the feature recent-list predates the feature calendar-sync and,
54
+    // consequently, the feature known-domains, it's possible for the feature
55
+    // known-list to know of domains which the feature known-domains is yet to
56
+    // discover.
57
+    const knownDomains = [];
42 58
 
43
-        dispatch(storeCurrentConference(locationURL));
59
+    for (const { conference } of getState()['features/recent-list']) {
60
+        const uri = parseURIString(conference);
61
+        let host;
62
+
63
+        uri && (host = uri.host) && knownDomains.push(host);
44 64
     }
65
+    knownDomains.length && dispatch(addKnownDomains(knownDomains));
66
+
67
+    return result;
45 68
 }
46 69
 
47 70
 /**
48 71
  * Updates the duration of the last conference stored in the list.
49 72
  *
50 73
  * @param {Store} store - The redux store.
74
+ * @param {Dispatch} next - The redux {@code dispatch} function.
75
+ * @param {Action} action - The redux action {@link CONFERENCE_WILL_LEAVE}.
51 76
  * @private
52
- * @returns {void}
77
+ * @returns {*} The result returned by {@code next(action)}.
53 78
  */
54
-function _updateConferenceDuration({ dispatch, getState }) {
55
-    const { locationURL } = getState()['features/base/connection'];
79
+function _conferenceWillLeave({ dispatch, getState }, next, action) {
80
+    dispatch(
81
+        _updateConferenceDuration(
82
+            getState()['features/base/connection'].locationURL));
56 83
 
57
-    dispatch(updateConferenceDuration(locationURL));
84
+    return next(action);
85
+}
86
+
87
+/**
88
+ * Checks if there is a current conference (upon SET_ROOM action), and saves it
89
+ * if necessary.
90
+ *
91
+ * @param {Store} store - The redux store.
92
+ * @param {Dispatch} next - The redux {@code dispatch} function.
93
+ * @param {Action} action - The redux action {@link SET_ROOM}.
94
+ * @private
95
+ * @returns {*} The result returned by {@code next(action)}.
96
+ */
97
+function _setRoom({ dispatch, getState }, next, action) {
98
+    if (action.room) {
99
+        const { locationURL } = getState()['features/base/connection'];
100
+
101
+        if (locationURL) {
102
+            dispatch(_storeCurrentConference(locationURL));
103
+
104
+            // Whatever domain the feature recent-list knows about, the app as a
105
+            // whole should know about.
106
+            //
107
+            // XXX Technically, _storeCurrentConference could be turned into an
108
+            // asynchronous action creator which dispatches both
109
+            // _STORE_CURRENT_CONFERENCE and addKnownDomains but...
110
+            dispatch(addKnownDomains(locationURL.host));
111
+        }
112
+    }
113
+
114
+    return next(action);
58 115
 }

+ 4
- 4
react/features/recent-list/reducer.js View File

@@ -6,8 +6,8 @@ import { ReducerRegistry } from '../base/redux';
6 6
 import { PersistenceRegistry } from '../base/storage';
7 7
 
8 8
 import {
9
-    STORE_CURRENT_CONFERENCE,
10
-    UPDATE_CONFERENCE_DURATION
9
+    _STORE_CURRENT_CONFERENCE,
10
+    _UPDATE_CONFERENCE_DURATION
11 11
 } from './actionTypes';
12 12
 
13 13
 const logger = require('jitsi-meet-logger').getLogger(__filename);
@@ -54,10 +54,10 @@ ReducerRegistry.register(
54 54
         case APP_WILL_MOUNT:
55 55
             return _appWillMount(state);
56 56
 
57
-        case STORE_CURRENT_CONFERENCE:
57
+        case _STORE_CURRENT_CONFERENCE:
58 58
             return _storeCurrentConference(state, action);
59 59
 
60
-        case UPDATE_CONFERENCE_DURATION:
60
+        case _UPDATE_CONFERENCE_DURATION:
61 61
             return _updateConferenceDuration(state, action);
62 62
 
63 63
         default:

Loading…
Cancel
Save