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 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<IState> {
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<IState> {
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") {