|
@@ -6,11 +6,26 @@ import {
|
6
|
6
|
STORE_CURRENT_CONFERENCE,
|
7
|
7
|
UPDATE_CONFERENCE_DURATION
|
8
|
8
|
} from './actionTypes';
|
9
|
|
-import { LIST_SIZE } from './constants';
|
10
|
|
-import { getLegacyRecentRoomList } from './functions';
|
|
9
|
+
|
|
10
|
+const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
11
|
+
|
|
12
|
+/**
|
|
13
|
+ * The name of the {@code window.localStorage} item where recent rooms are
|
|
14
|
+ * stored.
|
|
15
|
+ *
|
|
16
|
+ * @type {string}
|
|
17
|
+ */
|
|
18
|
+const LEGACY_STORAGE_KEY = 'recentURLs';
|
11
|
19
|
|
12
|
20
|
/**
|
13
|
|
- * The Redux subtree of this feature.
|
|
21
|
+ * The max size of the list.
|
|
22
|
+ *
|
|
23
|
+ * @type {number}
|
|
24
|
+ */
|
|
25
|
+export const MAX_LIST_SIZE = 30;
|
|
26
|
+
|
|
27
|
+/**
|
|
28
|
+ * The redux subtree of this feature.
|
14
|
29
|
*/
|
15
|
30
|
const STORE_NAME = 'features/recent-list';
|
16
|
31
|
|
|
@@ -22,22 +37,42 @@ PersistencyRegistry.register(STORE_NAME, {
|
22
|
37
|
});
|
23
|
38
|
|
24
|
39
|
/**
|
25
|
|
- * Reduces the Redux actions of the feature features/recent-list.
|
|
40
|
+ * Reduces the redux actions of the feature features/recent-list.
|
|
41
|
+ */
|
|
42
|
+ReducerRegistry.register(
|
|
43
|
+ STORE_NAME,
|
|
44
|
+ (state = { list: _getLegacyRecentRoomList() }, action) => {
|
|
45
|
+ switch (action.type) {
|
|
46
|
+ case STORE_CURRENT_CONFERENCE:
|
|
47
|
+ return _storeCurrentConference(state, action);
|
|
48
|
+
|
|
49
|
+ case UPDATE_CONFERENCE_DURATION:
|
|
50
|
+ return _updateConferenceDuration(state, action);
|
|
51
|
+
|
|
52
|
+ default:
|
|
53
|
+ return state;
|
|
54
|
+ }
|
|
55
|
+ });
|
|
56
|
+
|
|
57
|
+/**
|
|
58
|
+ * Retrieves the recent room list that was stored using the legacy way.
|
|
59
|
+ *
|
|
60
|
+ * @returns {Array<Object>}
|
26
|
61
|
*/
|
27
|
|
-ReducerRegistry.register(STORE_NAME, (state = {
|
28
|
|
- list: getLegacyRecentRoomList()
|
29
|
|
-}, action) => {
|
30
|
|
- switch (action.type) {
|
31
|
|
- case STORE_CURRENT_CONFERENCE:
|
32
|
|
- return _storeCurrentConference(state, action);
|
33
|
|
-
|
34
|
|
- case UPDATE_CONFERENCE_DURATION:
|
35
|
|
- return _updateConferenceDuration(state, action);
|
36
|
|
-
|
37
|
|
- default:
|
38
|
|
- return state;
|
|
62
|
+export function _getLegacyRecentRoomList(): Array<Object> {
|
|
63
|
+ try {
|
|
64
|
+ const list
|
|
65
|
+ = JSON.parse(window.localStorage.getItem(LEGACY_STORAGE_KEY));
|
|
66
|
+
|
|
67
|
+ if (list && list.length) {
|
|
68
|
+ return list;
|
|
69
|
+ }
|
|
70
|
+ } catch (error) {
|
|
71
|
+ logger.warn('Failed to parse legacy recent-room list!');
|
39
|
72
|
}
|
40
|
|
-});
|
|
73
|
+
|
|
74
|
+ return [];
|
|
75
|
+}
|
41
|
76
|
|
42
|
77
|
/**
|
43
|
78
|
* Adds a new list entry to the redux store.
|
|
@@ -54,15 +89,15 @@ function _storeCurrentConference(state, action) {
|
54
|
89
|
// it to the top.
|
55
|
90
|
const list = state.list.filter(e => e.conference !== conference);
|
56
|
91
|
|
57
|
|
- // This is a reverse sorted array (i.e. newer elements at the end).
|
|
92
|
+ // The list is a reverse-sorted (i.e. the newer elements are at the end).
|
58
|
93
|
list.push({
|
59
|
94
|
conference,
|
60
|
|
- conferenceDuration: 0, // we don't have this data yet
|
|
95
|
+ conferenceDuration: 0, // We don't have this data yet!
|
61
|
96
|
date: Date.now()
|
62
|
97
|
});
|
63
|
98
|
|
64
|
|
- // maximising the size
|
65
|
|
- list.splice(0, list.length - LIST_SIZE);
|
|
99
|
+ // Ensure the list doesn't exceed a/the maximum size.
|
|
100
|
+ list.splice(0, list.length - MAX_LIST_SIZE);
|
66
|
101
|
|
67
|
102
|
return {
|
68
|
103
|
list
|