Make getLastViewedRoomsStorageKey() make sense

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-04-20 13:24:23 +02:00
parent 1934c4a32f
commit d4ca087c2e
No known key found for this signature in database
GPG Key ID: 9760693FDD98A790
1 changed files with 6 additions and 11 deletions

View File

@ -42,9 +42,6 @@ interface IState {}
const ACTIVE_SPACE_LS_KEY = "mx_active_space"; const ACTIVE_SPACE_LS_KEY = "mx_active_space";
const LAST_VIEWED_ROOMS_HOME = "home_space";
export const HOME_SPACE = Symbol("home-space"); export const HOME_SPACE = Symbol("home-space");
export const SUGGESTED_ROOMS = Symbol("suggested-rooms"); 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 MAX_SUGGESTED_ROOMS = 20;
const getLastViewedRoomsStorageKey = (spaceId?) => { const getLastViewedRoomsStorageKey = (space?: Room) => {
if (!spaceId) return null; const lastViewRooms = "mx_last_viewed_rooms";
return `mx_last_viewed_rooms_${spaceId}`; const homeSpace = "home_space";
return `${lastViewRooms}_${space?.roomId || homeSpace}`;
} }
const partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => { // [spaces, rooms] const partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => { // [spaces, rooms]
@ -120,8 +118,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
this.emit(SUGGESTED_ROOMS, this._suggestedRooms = []); this.emit(SUGGESTED_ROOMS, this._suggestedRooms = []);
// view last selected room from space // view last selected room from space
const spaceId = space?.roomId || LAST_VIEWED_ROOMS_HOME; const roomId = window.localStorage.getItem(getLastViewedRoomsStorageKey(this.activeSpace));
const roomId = window.localStorage.getItem(getLastViewedRoomsStorageKey(spaceId));
if (roomId && this.matrixClient.getRoom(roomId).getMyMembership() === "join") { if (roomId && this.matrixClient.getRoom(roomId).getMyMembership() === "join") {
defaultDispatcher.dispatch({ defaultDispatcher.dispatch({
@ -517,10 +514,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
const room = this.matrixClient?.getRoom(payload.room_id); const room = this.matrixClient?.getRoom(payload.room_id);
// persist last viewed room from a space // persist last viewed room from a space
if (room) { if (room) {
const activeSpaceId = this.activeSpace?.roomId || LAST_VIEWED_ROOMS_HOME; window.localStorage.setItem(getLastViewedRoomsStorageKey(this.activeSpace), payload.room_id);
window.localStorage.setItem(getLastViewedRoomsStorageKey(activeSpaceId), payload.room_id);
} }
if (room?.getMyMembership() === "join") { if (room?.getMyMembership() === "join") {