Move persisting of last viewed into SpaceStore

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-03-26 07:53:07 +01:00
parent 67dcb3a448
commit 2dcb60b489
No known key found for this signature in database
GPG key ID: 9760693FDD98A790
2 changed files with 9 additions and 9 deletions

View file

@ -79,7 +79,7 @@ import { CommunityPrototypeStore } from "../../stores/CommunityPrototypeStore";
import DialPadModal from "../views/voip/DialPadModal";
import { showToast as showMobileGuideToast } from '../../toasts/MobileGuideToast';
import { shouldUseLoginForWelcome } from "../../utils/pages";
import SpaceStore, {LAST_VIEWED_ROOMS, LAST_VIEWED_ROOMS_HOME} from "../../stores/SpaceStore";
import SpaceStore from "../../stores/SpaceStore";
import SpaceRoomDirectory from "./SpaceRoomDirectory";
import {replaceableComponent} from "../../utils/replaceableComponent";
import RoomListStore from "../../stores/room-list/RoomListStore";
@ -875,14 +875,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private viewRoom(roomInfo: IRoomInfo) {
this.focusComposer = true;
// persist last viewed room from a space
const activeSpace = SpaceStore.instance.activeSpace;
const activeSpaceId = activeSpace?.roomId || LAST_VIEWED_ROOMS_HOME;
const lastViewedRooms = JSON.parse(window.localStorage.getItem(LAST_VIEWED_ROOMS)) || {};
lastViewedRooms[activeSpaceId] = roomInfo.room_id;
window.localStorage.setItem(LAST_VIEWED_ROOMS, JSON.stringify(lastViewedRooms));
if (roomInfo.room_alias) {
console.log(
`Switching to room alias ${roomInfo.room_alias} at event ` +

View file

@ -490,6 +490,14 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
if (!SettingsStore.getValue("feature_spaces")) return;
switch (payload.action) {
case "view_room": {
// persist last viewed room from a space
const activeSpace = SpaceStore.instance.activeSpace;
const activeSpaceId = activeSpace?.roomId || LAST_VIEWED_ROOMS_HOME;
const lastViewedRooms = JSON.parse(window.localStorage.getItem(LAST_VIEWED_ROOMS)) || {};
lastViewedRooms[activeSpaceId] = payload.room_id;
window.localStorage.setItem(LAST_VIEWED_ROOMS, JSON.stringify(lastViewedRooms));
const room = this.matrixClient?.getRoom(payload.room_id);
if (room?.getMyMembership() === "join") {