From adfecf0778838b7167c1264b4125e6d2d9fdef73 Mon Sep 17 00:00:00 2001 From: Kaki In <91763754+Kaki-In@users.noreply.github.com> Date: Tue, 26 Jul 2022 10:02:20 +0200 Subject: [PATCH] Fix restoring the last url at start The last session url is now remembered for being restored at the beginning of the session. Thanks for the help of @bwindels --- src/domain/navigation/URLRouter.js | 4 ++-- src/matrix/common.js | 18 +++++++++--------- src/platform/web/dom/History.js | 5 +++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/domain/navigation/URLRouter.js b/src/domain/navigation/URLRouter.js index 586eec8a..ab5dc5ce 100644 --- a/src/domain/navigation/URLRouter.js +++ b/src/domain/navigation/URLRouter.js @@ -27,7 +27,7 @@ export class URLRouter { } _getLastSessionId() { - const navPath = this._urlAsNavPath(this._history.getLastUrl() || ""); + const navPath = this._urlAsNavPath(this._history.getLastSessionUrl() || ""); const sessionId = navPath.get("session")?.value; if (typeof sessionId === "string") { return sessionId; @@ -84,7 +84,7 @@ export class URLRouter { } tryRestoreLastUrl() { - const lastNavPath = this._urlAsNavPath(this._history.getLastUrl() || ""); + const lastNavPath = this._urlAsNavPath(this._history.getLastSessionUrl() || ""); if (lastNavPath.segments.length !== 0) { this._applyNavPathToNavigation(lastNavPath); return true; diff --git a/src/matrix/common.js b/src/matrix/common.js index ba7876ed..abd74a57 100644 --- a/src/matrix/common.js +++ b/src/matrix/common.js @@ -22,16 +22,16 @@ export function makeTxnId() { } export function isTxnId(txnId) { - return txnId.startsWith("t") && txnId.length === 15; + return txnId.startsWith("t") && txnId.length === 15; } export function tests() { - return { - "isTxnId succeeds on result of makeTxnId": assert => { - assert(isTxnId(makeTxnId())); - }, - "isTxnId fails on event id": assert => { - assert(!isTxnId("$yS_n5n3cIO2aTtek0_2ZSlv-7g4YYR2zKrk2mFCW_rm")); - }, - } + return { + "isTxnId succeeds on result of makeTxnId": assert => { + assert(isTxnId(makeTxnId())); + }, + "isTxnId fails on event id": assert => { + assert(!isTxnId("$yS_n5n3cIO2aTtek0_2ZSlv-7g4YYR2zKrk2mFCW_rm")); + }, + } } diff --git a/src/platform/web/dom/History.js b/src/platform/web/dom/History.js index d51974bb..49102e5c 100644 --- a/src/platform/web/dom/History.js +++ b/src/platform/web/dom/History.js @@ -65,6 +65,7 @@ export class History extends BaseObservableValue { } onSubscribeFirst() { + this._lastSessionHash = window.localStorage?.getItem("hydrogen_last_url_hash"); window.addEventListener('hashchange', this); } @@ -76,7 +77,7 @@ export class History extends BaseObservableValue { window.localStorage?.setItem("hydrogen_last_url_hash", hash); } - getLastUrl() { - return window.localStorage?.getItem("hydrogen_last_url_hash"); + getLastSessionUrl() { + return this._lastSessionHash; } }