translate last-session to a real session id

This commit is contained in:
Bruno Windels 2021-05-18 13:52:13 +02:00
parent 63620ce59a
commit 1bec1033d1
2 changed files with 18 additions and 2 deletions

View File

@ -23,6 +23,14 @@ export class URLRouter {
this._subscription = null; this._subscription = null;
this._pathSubscription = null; this._pathSubscription = null;
this._isApplyingUrl = false; this._isApplyingUrl = false;
this._defaultSessionId = this._getLastSessionId();
}
_getLastSessionId() {
const urlPath = this._history.urlAsPath(this._history.getLastUrl());
const navPath = this._navigation.pathFrom(this._parseUrlPath(urlPath, this._navigation.path));
return navPath.get("session")?.value;
} }
attach() { attach() {
@ -50,7 +58,7 @@ export class URLRouter {
_applyUrl(url) { _applyUrl(url) {
const urlPath = this._history.urlAsPath(url) const urlPath = this._history.urlAsPath(url)
const navPath = this._navigation.pathFrom(this._parseUrlPath(urlPath, this._navigation.path)); const navPath = this._navigation.pathFrom(this._parseUrlPath(urlPath, this._navigation.path, this._defaultSessionId));
// this will cause _applyNavigationPath to be called, // this will cause _applyNavigationPath to be called,
// so set a flag whether this request came from ourselves // so set a flag whether this request came from ourselves
// (in which case it is a redirect if the url does not match the current one) // (in which case it is a redirect if the url does not match the current one)

View File

@ -85,7 +85,7 @@ function roomsSegmentWithRoom(rooms, roomId, path) {
} }
} }
export function parseUrlPath(urlPath, currentNavPath) { export function parseUrlPath(urlPath, currentNavPath, defaultSessionId) {
// substr(1) to take of initial / // substr(1) to take of initial /
const parts = urlPath.substr(1).split("/"); const parts = urlPath.substr(1).split("/");
const iterator = parts[Symbol.iterator](); const iterator = parts[Symbol.iterator]();
@ -113,6 +113,14 @@ export function parseUrlPath(urlPath, currentNavPath) {
segments.push(roomsSegmentWithRoom(rooms, roomId, currentNavPath)); segments.push(roomsSegmentWithRoom(rooms, roomId, currentNavPath));
} }
segments.push(new Segment("room", roomId)); segments.push(new Segment("room", roomId));
} else if (type === "last-session") {
let sessionSegment = currentNavPath.get("session");
if (!sessionSegment?.value && defaultSessionId) {
sessionSegment = new Segment("session", defaultSessionId);
}
if (sessionSegment) {
segments.push(sessionSegment);
}
} else { } else {
// might be undefined, which will be turned into true by Segment // might be undefined, which will be turned into true by Segment
const value = iterator.next().value; const value = iterator.next().value;