Преглед изворни кода

[RN] Fix legacy recent-list storage

master
Lyubo Marinov пре 7 година
родитељ
комит
83243d5980

+ 0
- 6
react/features/recent-list/constants.js Прегледај датотеку

@@ -1,6 +0,0 @@
1
-/**
2
- * The max size of the list.
3
- *
4
- * @type {number}
5
- */
6
-export const LIST_SIZE = 30;

+ 1
- 32
react/features/recent-list/functions.js Прегледај датотеку

@@ -31,42 +31,11 @@ require('moment/locale/zh-cn');
31 31
 import { i18next } from '../base/i18n';
32 32
 import { parseURIString } from '../base/util';
33 33
 
34
-const logger = require('jitsi-meet-logger').getLogger(__filename);
35
-
36
-/**
37
- * The name of the {@code window.localStorage} item where recent rooms are
38
- * stored.
39
- *
40
- * @type {string}
41
- */
42
-const RECENT_URL_STORAGE = 'recentURLs';
43
-
44
-/**
45
- * Retrieves the recent room list that was stored using the legacy way.
46
- *
47
- * @returns {Array<Object>}
48
- */
49
-export function getLegacyRecentRoomList(): Array<Object> {
50
-    const legacyListString = window.localStorage.getItem(RECENT_URL_STORAGE);
51
-
52
-    try {
53
-        const legacyList = JSON.parse(legacyListString);
54
-
55
-        if (legacyList && legacyList.length) {
56
-            return legacyList;
57
-        }
58
-    } catch (error) {
59
-        logger.warn('Unable to parse legacy recent list');
60
-    }
61
-
62
-    return [];
63
-}
64
-
65 34
 /**
66 35
  * Retrieves the recent room list and generates all the data needed to be
67 36
  * displayed.
68 37
  *
69
- * @param {Array<Object>} list - The stored recent list retrieved from Redux.
38
+ * @param {Array<Object>} list - The stored recent list retrieved from redux.
70 39
  * @returns {Array}
71 40
  */
72 41
 export function getRecentRooms(list: Array<Object>): Array<Object> {

+ 56
- 21
react/features/recent-list/reducer.js Прегледај датотеку

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

Loading…
Откажи
Сачувај