mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 05:04:57 +08:00
Merge pull request #5795 from SimonBrandner/spaces/context-switching
[Spaces] Context switching
This commit is contained in:
commit
b2e9f6731b
@ -51,6 +51,12 @@ export const UPDATE_SELECTED_SPACE = Symbol("selected-space");
|
|||||||
|
|
||||||
const MAX_SUGGESTED_ROOMS = 20;
|
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 partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => { // [spaces, rooms]
|
const partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => { // [spaces, rooms]
|
||||||
return arr.reduce((result, room: Room) => {
|
return arr.reduce((result, room: Room) => {
|
||||||
result[room.isSpaceRoom() ? 0 : 1].push(room);
|
result[room.isSpaceRoom() ? 0 : 1].push(room);
|
||||||
@ -111,6 +117,25 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||||||
this.emit(UPDATE_SELECTED_SPACE, this.activeSpace);
|
this.emit(UPDATE_SELECTED_SPACE, this.activeSpace);
|
||||||
this.emit(SUGGESTED_ROOMS, this._suggestedRooms = []);
|
this.emit(SUGGESTED_ROOMS, this._suggestedRooms = []);
|
||||||
|
|
||||||
|
// view last selected room from space
|
||||||
|
const roomId = window.localStorage.getItem(getLastViewedRoomsStorageKey(this.activeSpace));
|
||||||
|
|
||||||
|
if (roomId && this.matrixClient?.getRoom(roomId)?.getMyMembership() === "join") {
|
||||||
|
defaultDispatcher.dispatch({
|
||||||
|
action: "view_room",
|
||||||
|
room_id: roomId,
|
||||||
|
});
|
||||||
|
} else if (space) {
|
||||||
|
defaultDispatcher.dispatch({
|
||||||
|
action: "view_room",
|
||||||
|
room_id: space.roomId,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
defaultDispatcher.dispatch({
|
||||||
|
action: "view_home_page",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// persist space selected
|
// persist space selected
|
||||||
if (space) {
|
if (space) {
|
||||||
window.localStorage.setItem(ACTIVE_SPACE_LS_KEY, space.roomId);
|
window.localStorage.setItem(ACTIVE_SPACE_LS_KEY, space.roomId);
|
||||||
@ -488,6 +513,11 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||||||
case "view_room": {
|
case "view_room": {
|
||||||
const room = this.matrixClient?.getRoom(payload.room_id);
|
const room = this.matrixClient?.getRoom(payload.room_id);
|
||||||
|
|
||||||
|
// persist last viewed room from a space
|
||||||
|
if (room) {
|
||||||
|
window.localStorage.setItem(getLastViewedRoomsStorageKey(this.activeSpace), payload.room_id);
|
||||||
|
}
|
||||||
|
|
||||||
if (room?.getMyMembership() === "join") {
|
if (room?.getMyMembership() === "join") {
|
||||||
if (room.isSpaceRoom()) {
|
if (room.isSpaceRoom()) {
|
||||||
this.setActiveSpace(room);
|
this.setActiveSpace(room);
|
||||||
|
Loading…
Reference in New Issue
Block a user