Add getLastViewedRoomsStorageKey()

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-04-20 12:39:11 +02:00
parent f9292c364c
commit 1934c4a32f
No known key found for this signature in database
GPG key ID: 9760693FDD98A790

View file

@ -41,7 +41,7 @@ type SpaceKey = string | symbol;
interface IState {}
const ACTIVE_SPACE_LS_KEY = "mx_active_space";
const LAST_VIEWED_ROOMS = "mx_last_viewed_rooms";
const LAST_VIEWED_ROOMS_HOME = "home_space";
@ -54,6 +54,11 @@ 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 partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => { // [spaces, rooms]
return arr.reduce((result, room: Room) => {
result[room.isSpaceRoom() ? 0 : 1].push(room);
@ -116,7 +121,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
// view last selected room from space
const spaceId = space?.roomId || LAST_VIEWED_ROOMS_HOME;
const roomId = window.localStorage.getItem(`${LAST_VIEWED_ROOMS}_${spaceId}`);
const roomId = window.localStorage.getItem(getLastViewedRoomsStorageKey(spaceId));
if (roomId && this.matrixClient.getRoom(roomId).getMyMembership() === "join") {
defaultDispatcher.dispatch({
@ -515,7 +520,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
if (room) {
const activeSpaceId = this.activeSpace?.roomId || LAST_VIEWED_ROOMS_HOME;
window.localStorage.setItem(`${LAST_VIEWED_ROOMS}_${activeSpaceId}`, payload.room_id);
window.localStorage.setItem(getLastViewedRoomsStorageKey(activeSpaceId), payload.room_id);
}
if (room?.getMyMembership() === "join") {