From d4ca087c2eb6fe342a89cdb7ed7491edb2f7dd25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 20 Apr 2021 13:24:23 +0200 Subject: [PATCH] Make getLastViewedRoomsStorageKey() make sense MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/stores/SpaceStore.tsx | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/stores/SpaceStore.tsx b/src/stores/SpaceStore.tsx index a7efbafd1e..eeecbbeba1 100644 --- a/src/stores/SpaceStore.tsx +++ b/src/stores/SpaceStore.tsx @@ -42,9 +42,6 @@ interface IState {} const ACTIVE_SPACE_LS_KEY = "mx_active_space"; - -const LAST_VIEWED_ROOMS_HOME = "home_space"; - export const HOME_SPACE = Symbol("home-space"); export const SUGGESTED_ROOMS = Symbol("suggested-rooms"); @@ -54,9 +51,10 @@ export const UPDATE_SELECTED_SPACE = Symbol("selected-space"); const MAX_SUGGESTED_ROOMS = 20; -const getLastViewedRoomsStorageKey = (spaceId?) => { - if (!spaceId) return null; - return `mx_last_viewed_rooms_${spaceId}`; +const getLastViewedRoomsStorageKey = (space?: Room) => { + const lastViewRooms = "mx_last_viewed_rooms"; + const homeSpace = "home_space"; + return `${lastViewRooms}_${space?.roomId || homeSpace}`; } const partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => { // [spaces, rooms] @@ -120,8 +118,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient { this.emit(SUGGESTED_ROOMS, this._suggestedRooms = []); // view last selected room from space - const spaceId = space?.roomId || LAST_VIEWED_ROOMS_HOME; - const roomId = window.localStorage.getItem(getLastViewedRoomsStorageKey(spaceId)); + const roomId = window.localStorage.getItem(getLastViewedRoomsStorageKey(this.activeSpace)); if (roomId && this.matrixClient.getRoom(roomId).getMyMembership() === "join") { defaultDispatcher.dispatch({ @@ -517,10 +514,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient { const room = this.matrixClient?.getRoom(payload.room_id); // persist last viewed room from a space - if (room) { - const activeSpaceId = this.activeSpace?.roomId || LAST_VIEWED_ROOMS_HOME; - window.localStorage.setItem(getLastViewedRoomsStorageKey(activeSpaceId), payload.room_id); + window.localStorage.setItem(getLastViewedRoomsStorageKey(this.activeSpace), payload.room_id); } if (room?.getMyMembership() === "join") {