Reset space contexts as some users may have loops stuck in their local storage

pull/21833/head
Michael Telatynski 2021-04-22 09:05:02 +01:00
parent b64b956aa4
commit 28fa1cb44c
1 changed files with 3 additions and 7 deletions

View File

@ -51,11 +51,7 @@ export const UPDATE_SELECTED_SPACE = Symbol("selected-space");
const MAX_SUGGESTED_ROOMS = 20;
const getLastViewedRoomsStorageKey = (space?: Room) => {
const lastViewRooms = "mx_last_viewed_rooms";
const homeSpace = "home_space";
return `${lastViewRooms}_${space?.roomId || homeSpace}`;
}
const getSpaceContextKey = (space?: Room) => `mx_space_context_${space?.roomId || "home_space"}`;
const partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => { // [spaces, rooms]
return arr.reduce((result, room: Room) => {
@ -119,7 +115,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
if (contextSwitch) {
// view last selected room from space
const roomId = window.localStorage.getItem(getLastViewedRoomsStorageKey(this.activeSpace));
const roomId = window.localStorage.getItem(getSpaceContextKey(this.activeSpace));
if (roomId && this.matrixClient?.getRoom(roomId)?.getMyMembership() === "join") {
defaultDispatcher.dispatch({
@ -542,7 +538,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
// Persist last viewed room from a space
// we don't await setActiveSpace above as we only care about this.activeSpace being up to date
// synchronously for the below code - everything else can and should be async.
window.localStorage.setItem(getLastViewedRoomsStorageKey(this.activeSpace), payload.room_id);
window.localStorage.setItem(getSpaceContextKey(this.activeSpace), payload.room_id);
break;
}
case "after_leave_room":