mirror of https://github.com/vector-im/riot-web
Make getLastViewedRoomsStorageKey() make sense
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>pull/21833/head
parent
1934c4a32f
commit
d4ca087c2e
|
@ -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") {
|
||||
|
|
Loading…
Reference in New Issue