From 1bec1033d12b8af2954f6282ace568018ef76c07 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 18 May 2021 13:52:13 +0200 Subject: [PATCH] translate last-session to a real session id --- src/domain/navigation/URLRouter.js | 10 +++++++++- src/domain/navigation/index.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/domain/navigation/URLRouter.js b/src/domain/navigation/URLRouter.js index 36a1c244..ab6c9205 100644 --- a/src/domain/navigation/URLRouter.js +++ b/src/domain/navigation/URLRouter.js @@ -23,6 +23,14 @@ export class URLRouter { this._subscription = null; this._pathSubscription = null; 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() { @@ -50,7 +58,7 @@ export class URLRouter { _applyUrl(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, // 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) diff --git a/src/domain/navigation/index.js b/src/domain/navigation/index.js index 5de73aef..34151c62 100644 --- a/src/domain/navigation/index.js +++ b/src/domain/navigation/index.js @@ -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 / const parts = urlPath.substr(1).split("/"); const iterator = parts[Symbol.iterator](); @@ -113,6 +113,14 @@ export function parseUrlPath(urlPath, currentNavPath) { segments.push(roomsSegmentWithRoom(rooms, roomId, currentNavPath)); } 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 { // might be undefined, which will be turned into true by Segment const value = iterator.next().value;