mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Merge pull request #816 from Kaki-In/restore_last
Opening the last opened room at start
This commit is contained in:
commit
02116103a1
@ -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;
|
||||
|
@ -17,6 +17,12 @@ limitations under the License.
|
||||
import {BaseObservableValue} from "../../../observable/ObservableValue";
|
||||
|
||||
export class History extends BaseObservableValue {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._lastSessionHash = undefined;
|
||||
}
|
||||
|
||||
handleEvent(event) {
|
||||
if (event.type === "hashchange") {
|
||||
this.emit(this.get());
|
||||
@ -65,6 +71,7 @@ export class History extends BaseObservableValue {
|
||||
}
|
||||
|
||||
onSubscribeFirst() {
|
||||
this._lastSessionHash = window.localStorage?.getItem("hydrogen_last_url_hash");
|
||||
window.addEventListener('hashchange', this);
|
||||
}
|
||||
|
||||
@ -76,7 +83,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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user