From 6e05cab46e624474d3ae86801d6536b993f70215 Mon Sep 17 00:00:00 2001 From: Zoltan Bettenbuk Date: Thu, 1 Feb 2018 22:33:18 -0600 Subject: [PATCH] [RN] Fix legacy recent-list storage --- react/features/recent-list/constants.js | 8 ------- react/features/recent-list/functions.js | 31 +++++++++++++++++++++++++ react/features/recent-list/reducer.js | 12 ++++------ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/react/features/recent-list/constants.js b/react/features/recent-list/constants.js index fa9205888..85cd187cb 100644 --- a/react/features/recent-list/constants.js +++ b/react/features/recent-list/constants.js @@ -4,11 +4,3 @@ * @type {number} */ export const LIST_SIZE = 30; - -/** - * The name of the {@code window.localStorage} item where recent rooms are - * stored. - * - * @type {string} - */ -export const RECENT_URL_STORAGE = 'recentURLs'; diff --git a/react/features/recent-list/functions.js b/react/features/recent-list/functions.js index c8e2809db..96160d672 100644 --- a/react/features/recent-list/functions.js +++ b/react/features/recent-list/functions.js @@ -31,6 +31,37 @@ require('moment/locale/zh-cn'); import { i18next } from '../base/i18n'; import { parseURIString } from '../base/util'; +const logger = require('jitsi-meet-logger').getLogger(__filename); + +/** + * The name of the {@code window.localStorage} item where recent rooms are + * stored. + * + * @type {string} + */ +const RECENT_URL_STORAGE = 'recentURLs'; + +/** + * Retrieves the recent room list that was stored using the legacy way. + * + * @returns {Array} + */ +export function getLegacyRecentRoomList(): Array { + const legacyListString = window.localStorage.getItem(RECENT_URL_STORAGE); + + try { + const legacyList = JSON.parse(legacyListString); + + if (legacyList && legacyList.length) { + return legacyList; + } + } catch (error) { + logger.warn('Unable to parse legacy recent list'); + } + + return []; +} + /** * Retrieves the recent room list and generates all the data needed to be * displayed. diff --git a/react/features/recent-list/reducer.js b/react/features/recent-list/reducer.js index ca4dcafe9..2024b97f1 100644 --- a/react/features/recent-list/reducer.js +++ b/react/features/recent-list/reducer.js @@ -7,13 +7,7 @@ import { UPDATE_CONFERENCE_DURATION } from './actionTypes'; import { LIST_SIZE } from './constants'; - -/** - * The initial state of this feature. - */ -const DEFAULT_STATE = { - list: [] -}; +import { getLegacyRecentRoomList } from './functions'; /** * The Redux subtree of this feature. @@ -30,7 +24,9 @@ PersistencyRegistry.register(STORE_NAME, { /** * Reduces the Redux actions of the feature features/recent-list. */ -ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => { +ReducerRegistry.register(STORE_NAME, (state = { + list: getLegacyRecentRoomList() +}, action) => { switch (action.type) { case STORE_CURRENT_CONFERENCE: return _storeCurrentConference(state, action);