Browse Source

Implement adaptive known domain list

master
zbettenbuk 7 years ago
parent
commit
cb973b61aa

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

4
  * Action to update the current calendar entry list in the store.
4
  * Action to update the current calendar entry list in the store.
5
  */
5
  */
6
 export const NEW_CALENDAR_ENTRY_LIST = Symbol('NEW_CALENDAR_ENTRY_LIST');
6
 export const NEW_CALENDAR_ENTRY_LIST = Symbol('NEW_CALENDAR_ENTRY_LIST');
7
+
8
+/**
9
+ * Action to add a new known domain to the list.
10
+ */
11
+export const NEW_KNOWN_DOMAIN = Symbol('NEW_KNOWN_DOMAIN');

+ 19
- 3
react/features/calendar-sync/actions.js View File

1
 // @flow
1
 // @flow
2
-import { NEW_CALENDAR_ENTRY_LIST } from './actionTypes';
2
+import { NEW_CALENDAR_ENTRY_LIST, NEW_KNOWN_DOMAIN } from './actionTypes';
3
 
3
 
4
 /**
4
 /**
5
  * Sends an action to update the current calendar list in redux.
5
  * Sends an action to update the current calendar list in redux.
6
  *
6
  *
7
  * @param {Array<Object>} events - The new list.
7
  * @param {Array<Object>} events - The new list.
8
  * @returns {{
8
  * @returns {{
9
- *  type: NEW_CALENDAR_ENTRY_LIST,
10
- *  events: Array<Object>
9
+ *   type: NEW_CALENDAR_ENTRY_LIST,
10
+ *   events: Array<Object>
11
  * }}
11
  * }}
12
  */
12
  */
13
 export function updateCalendarEntryList(events: Array<Object>) {
13
 export function updateCalendarEntryList(events: Array<Object>) {
16
         events
16
         events
17
     };
17
     };
18
 }
18
 }
19
+
20
+/**
21
+ * Sends an action to add a new known domain if not present yet.
22
+ *
23
+ * @param {string} domainName - The new domain.
24
+ * @returns {{
25
+ *   type: NEW_KNOWN_DOMAIN,
26
+ *   domainName: string
27
+ * }}
28
+ */
29
+export function maybeAddNewKnownDomain(domainName: string) {
30
+    return {
31
+        type: NEW_KNOWN_DOMAIN,
32
+        domainName
33
+    };
34
+}

+ 42
- 28
react/features/calendar-sync/middleware.js View File

2
 import Logger from 'jitsi-meet-logger';
2
 import Logger from 'jitsi-meet-logger';
3
 import RNCalendarEvents from 'react-native-calendar-events';
3
 import RNCalendarEvents from 'react-native-calendar-events';
4
 
4
 
5
+import { SET_ROOM } from '../base/conference';
5
 import { MiddlewareRegistry } from '../base/redux';
6
 import { MiddlewareRegistry } from '../base/redux';
7
+import { parseURIString } from '../base/util';
6
 
8
 
7
 import { APP_WILL_MOUNT } from '../app';
9
 import { APP_WILL_MOUNT } from '../app';
8
 
10
 
9
-import { updateCalendarEntryList } from './actions';
11
+import { maybeAddNewKnownDomain, updateCalendarEntryList } from './actions';
10
 
12
 
11
 const FETCH_END_DAYS = 10;
13
 const FETCH_END_DAYS = 10;
12
 const FETCH_START_DAYS = -1;
14
 const FETCH_START_DAYS = -1;
13
 const MAX_LIST_LENGTH = 10;
15
 const MAX_LIST_LENGTH = 10;
14
 const logger = Logger.getLogger(__filename);
16
 const logger = Logger.getLogger(__filename);
15
 
17
 
16
-// this is to be dynamic later.
17
-const domainList = [
18
-    'meet.jit.si',
19
-    'beta.meet.jit.si'
20
-];
21
-
22
 MiddlewareRegistry.register(store => next => action => {
18
 MiddlewareRegistry.register(store => next => action => {
23
     const result = next(action);
19
     const result = next(action);
24
 
20
 
25
     switch (action.type) {
21
     switch (action.type) {
26
     case APP_WILL_MOUNT:
22
     case APP_WILL_MOUNT:
23
+        _ensureDefaultServer(store);
27
         _fetchCalendarEntries(store);
24
         _fetchCalendarEntries(store);
25
+        break;
26
+    case SET_ROOM:
27
+        _parseAndAddDomain(store);
28
     }
28
     }
29
 
29
 
30
     return result;
30
     return result;
64
     });
64
     });
65
 }
65
 }
66
 
66
 
67
+/**
68
+ * Ensures presence of the default server in the known domains list.
69
+ *
70
+ * @private
71
+ * @param {Object} store - The redux store.
72
+ * @returns {Promise}
73
+ */
74
+function _ensureDefaultServer(store) {
75
+    const state = store.getState();
76
+    const defaultURL = parseURIString(
77
+        state['features/app'].app._getDefaultURL()
78
+    );
79
+
80
+    store.dispatch(maybeAddNewKnownDomain(defaultURL.host));
81
+}
82
+
67
 /**
83
 /**
68
  * Reads the user's calendar and updates the stored entries if need be.
84
  * Reads the user's calendar and updates the stored entries if need be.
69
  *
85
  *
86
             []
102
             []
87
         )
103
         )
88
         .then(events => {
104
         .then(events => {
105
+            const { knownDomains } = store.getState()['features/calendar-sync'];
89
             const eventList = [];
106
             const eventList = [];
90
 
107
 
91
             if (events && events.length) {
108
             if (events && events.length) {
92
                 for (const event of events) {
109
                 for (const event of events) {
93
-                    const jitsiURL = _getURLFromEvent(event);
110
+                    const jitsiURL = _getURLFromEvent(event, knownDomains);
94
                     const now = Date.now();
111
                     const now = Date.now();
95
 
112
 
96
                     if (jitsiURL) {
113
                     if (jitsiURL) {
117
                 }
134
                 }
118
             }
135
             }
119
 
136
 
120
-            // TEST events to check notification popup.
121
-            // TODO: Remove this before a PR.
122
-            eventList.push({
123
-                endDate: Date.now() + (60 * 60 * 1000),
124
-                id: -1,
125
-                startDate: Date.now() + (80 * 1000),
126
-                title: 'ShipIt 41',
127
-                url: 'https://meet.jit.si/shipit41'
128
-            });
129
-
130
-            eventList.push({
131
-                endDate: Date.now() + (2 * 60 * 60 * 1000),
132
-                id: -2,
133
-                startDate: Date.now() + (60 * 60 * 1000),
134
-                title: 'ShipIt 41 demo',
135
-                url: 'https://meet.jit.si/shipit41'
136
-            });
137
-
138
             store.dispatch(updateCalendarEntryList(eventList.sort((a, b) =>
137
             store.dispatch(updateCalendarEntryList(eventList.sort((a, b) =>
139
                 a.startDate - b.startDate
138
                 a.startDate - b.startDate
140
             ).slice(0, MAX_LIST_LENGTH)));
139
             ).slice(0, MAX_LIST_LENGTH)));
153
  *
152
  *
154
  * @private
153
  * @private
155
  * @param {Object} event - The event to parse.
154
  * @param {Object} event - The event to parse.
155
+ * @param {Array<string>} knownDomains - The known domain names.
156
  * @returns {string}
156
  * @returns {string}
157
  *
157
  *
158
  */
158
  */
159
-function _getURLFromEvent(event) {
159
+function _getURLFromEvent(event, knownDomains) {
160
     const urlRegExp
160
     const urlRegExp
161
-        = new RegExp(`http(s)?://(${domainList.join('|')})/[^\\s<>$]+`, 'gi');
161
+        = new RegExp(`http(s)?://(${knownDomains.join('|')})/[^\\s<>$]+`, 'gi');
162
     const fieldsToSearch = [
162
     const fieldsToSearch = [
163
         event.title,
163
         event.title,
164
         event.url,
164
         event.url,
180
 
180
 
181
     return null;
181
     return null;
182
 }
182
 }
183
+
184
+/**
185
+ * Retreives the domain name of a room upon join and stores it
186
+ * in the known domain list, if not present yet.
187
+ *
188
+ * @private
189
+ * @param {Object} store - The redux store.
190
+ * @returns {Promise}
191
+ */
192
+function _parseAndAddDomain(store) {
193
+    const { locationURL } = store.getState()['features/base/connection'];
194
+
195
+    store.dispatch(maybeAddNewKnownDomain(locationURL.host));
196
+}

+ 43
- 2
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';
4
 
5
 
5
-import { NEW_CALENDAR_ENTRY_LIST } from './actionTypes';
6
+import { NEW_CALENDAR_ENTRY_LIST, NEW_KNOWN_DOMAIN } from './actionTypes';
6
 
7
 
7
 /**
8
 /**
8
  * ZB: this is an object, as further data is to come here, like:
9
  * ZB: this is an object, as further data is to come here, like:
9
  * - known domain list
10
  * - known domain list
10
  */
11
  */
11
 const DEFAULT_STATE = {
12
 const DEFAULT_STATE = {
12
-    events: []
13
+    events: [],
14
+    knownDomains: []
13
 };
15
 };
16
+
17
+const MAX_DOMAIN_LIST_SIZE = 10;
18
+
14
 const STORE_NAME = 'features/calendar-sync';
19
 const STORE_NAME = 'features/calendar-sync';
15
 
20
 
21
+PersistenceRegistry.register(STORE_NAME, {
22
+    knownDomains: true
23
+});
24
+
16
 ReducerRegistry.register(
25
 ReducerRegistry.register(
17
     STORE_NAME,
26
     STORE_NAME,
18
     (state = DEFAULT_STATE, action) => {
27
     (state = DEFAULT_STATE, action) => {
19
         switch (action.type) {
28
         switch (action.type) {
20
         case NEW_CALENDAR_ENTRY_LIST:
29
         case NEW_CALENDAR_ENTRY_LIST:
21
             return {
30
             return {
31
+                ...state,
22
                 events: action.events
32
                 events: action.events
23
             };
33
             };
24
 
34
 
35
+        case NEW_KNOWN_DOMAIN:
36
+            return _maybeAddNewDomain(state, action);
37
+
25
         default:
38
         default:
26
             return state;
39
             return state;
27
         }
40
         }
28
     });
41
     });
42
+
43
+/**
44
+ * Adds a new domain to the known domain list if not present yet.
45
+ *
46
+ * @private
47
+ * @param {Object} state - The redux state.
48
+ * @param {Object} action - The redux action.
49
+ * @returns {Object}
50
+ */
51
+function _maybeAddNewDomain(state, action) {
52
+    let { domainName } = action;
53
+    const { knownDomains } = state;
54
+
55
+    if (domainName && domainName.length) {
56
+        domainName = domainName.toLowerCase();
57
+        if (knownDomains.indexOf(domainName) === -1) {
58
+            knownDomains.push(domainName);
59
+
60
+            // Ensure the list doesn't exceed a/the maximum size.
61
+            knownDomains.splice(0, knownDomains.length - MAX_DOMAIN_LIST_SIZE);
62
+        }
63
+    }
64
+
65
+    return {
66
+        ...state,
67
+        knownDomains
68
+    };
69
+}

Loading…
Cancel
Save