|
@@ -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
|
}
|