schildichat-desktop/patches/element-web/0016-On-space-switch-don-t-automatically-show-last-opened.patch

80 lines
3.5 KiB
Diff

From 89e083af2be11b17c756c6078a43ce1c6c305cc2 Mon Sep 17 00:00:00 2001
From: su-ex <codeworks@supercable.onl>
Date: Thu, 30 May 2024 14:35:16 +0200
Subject: On space switch don't automatically show last opened room
---
src/components/structures/MatrixChat.tsx | 18 +++++++++++++++++-
src/settings/Settings.tsx | 6 ++++++
src/stores/spaces/SpaceStore.ts | 1 +
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx
index d0edcccd4f..3146200c68 100644
--- a/src/components/structures/MatrixChat.tsx
+++ b/src/components/structures/MatrixChat.tsx
@@ -1457,7 +1457,15 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
if (this.screenAfterLogin && this.screenAfterLogin.screen) {
this.showScreen(this.screenAfterLogin.screen, this.screenAfterLogin.params);
this.screenAfterLogin = undefined;
- } else if (localStorage && localStorage.getItem("mx_last_room_id")) {
+ } else if (
+ !SettingsStore.getValue("Spaces.returnToPreviouslyOpenedRoom") &&
+ localStorage &&
+ localStorage.getItem("mx_active_space") &&
+ localStorage.getItem("mx_active_space")[0] === "!"
+ ) {
+ // SC: Show the last viewed space
+ this.viewLastSpace();
+ } else if (SettingsStore.getValue("Spaces.returnToPreviouslyOpenedRoom") && localStorage && localStorage.getItem("mx_last_room_id")) {
// Before defaulting to directory, show the last viewed room
this.viewLastRoom();
} else {
@@ -1469,6 +1477,14 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
}
}
+ private viewLastSpace(): void { // SC
+ // SC-ToDo: Make this work for meta spaces
+ dis.dispatch({
+ action: Action.ViewRoom,
+ room_id: localStorage.getItem("mx_active_space"),
+ });
+ }
+
private viewLastRoom(): void {
dis.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx
index 12d9965cf1..3e9fb95799 100644
--- a/src/settings/Settings.tsx
+++ b/src/settings/Settings.tsx
@@ -204,6 +204,12 @@ export const SETTINGS: { [setting: string]: ISetting } = {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
default: true,
},
+ "Spaces.returnToPreviouslyOpenedRoom": {
+ displayName: _td("Return to the room previously opened in a space"),
+ description: _td("If disabled, the space overview will be shown when switching to another space."),
+ supportedLevels: LEVELS_ACCOUNT_SETTINGS,
+ default: false,
+ },
// SC settings end
"feature_video_rooms": {
isFeature: true,
diff --git a/src/stores/spaces/SpaceStore.ts b/src/stores/spaces/SpaceStore.ts
index 60df05478a..0be7ba190a 100644
--- a/src/stores/spaces/SpaceStore.ts
+++ b/src/stores/spaces/SpaceStore.ts
@@ -265,6 +265,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
// else if the last viewed room in this space is joined then view that
// else view space home or home depending on what is being clicked on
if (
+ SettingsStore.getValue("Spaces.returnToPreviouslyOpenedRoom") &&
roomId &&
cliSpace?.getMyMembership() !== KnownMembership.Invite &&
this.matrixClient.getRoom(roomId)?.getMyMembership() === KnownMembership.Join &&
--
2.47.0