Merge pull request #816 from Kaki-In/restore_last

Opening the last opened room at start
This commit is contained in:
Bruno Windels 2022-07-29 10:16:23 +00:00 committed by GitHub
commit 02116103a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -27,7 +27,7 @@ export class URLRouter {
} }
_getLastSessionId() { _getLastSessionId() {
const navPath = this._urlAsNavPath(this._history.getLastUrl() || ""); const navPath = this._urlAsNavPath(this._history.getLastSessionUrl() || "");
const sessionId = navPath.get("session")?.value; const sessionId = navPath.get("session")?.value;
if (typeof sessionId === "string") { if (typeof sessionId === "string") {
return sessionId; return sessionId;
@ -84,7 +84,7 @@ export class URLRouter {
} }
tryRestoreLastUrl() { tryRestoreLastUrl() {
const lastNavPath = this._urlAsNavPath(this._history.getLastUrl() || ""); const lastNavPath = this._urlAsNavPath(this._history.getLastSessionUrl() || "");
if (lastNavPath.segments.length !== 0) { if (lastNavPath.segments.length !== 0) {
this._applyNavPathToNavigation(lastNavPath); this._applyNavPathToNavigation(lastNavPath);
return true; return true;

View File

@ -17,6 +17,12 @@ limitations under the License.
import {BaseObservableValue} from "../../../observable/ObservableValue"; import {BaseObservableValue} from "../../../observable/ObservableValue";
export class History extends BaseObservableValue { export class History extends BaseObservableValue {
constructor() {
super();
this._lastSessionHash = undefined;
}
handleEvent(event) { handleEvent(event) {
if (event.type === "hashchange") { if (event.type === "hashchange") {
this.emit(this.get()); this.emit(this.get());
@ -65,6 +71,7 @@ export class History extends BaseObservableValue {
} }
onSubscribeFirst() { onSubscribeFirst() {
this._lastSessionHash = window.localStorage?.getItem("hydrogen_last_url_hash");
window.addEventListener('hashchange', this); window.addEventListener('hashchange', this);
} }
@ -76,7 +83,7 @@ export class History extends BaseObservableValue {
window.localStorage?.setItem("hydrogen_last_url_hash", hash); window.localStorage?.setItem("hydrogen_last_url_hash", hash);
} }
getLastUrl() { getLastSessionUrl() {
return window.localStorage?.getItem("hydrogen_last_url_hash"); return this._lastSessionHash;
} }
} }