Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lightbox support and Hydrogen URL hashes relative to the room #12

Merged
merged 11 commits into from
Jun 8, 2022
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"node": true
},
"parserOptions": {
"ecmaVersion": 2018,
"ecmaVersion": 2022,
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
"sourceType": "script"
},
"plugins": ["node"],
Expand Down
7 changes: 6 additions & 1 deletion shared/hydrogen-vm-render-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const {
const ArchiveView = require('matrix-public-archive-shared/ArchiveView');
const RightPanelContentView = require('matrix-public-archive-shared/RightPanelContentView');
const MatrixPublicArchiveURLCreator = require('matrix-public-archive-shared/lib/url-creator');
const InMemoryHistory = require('matrix-public-archive-shared/lib/in-memory-history');

const fromTimestamp = window.matrixPublicArchiveContext.fromTimestamp;
assert(fromTimestamp);
Expand Down Expand Up @@ -87,11 +88,15 @@ async function mountHydrogen() {
});

const navigation = createNavigation();
const inMemoryHistory = new InMemoryHistory(roomData.id);
platform.setNavigation(navigation);
const urlRouter = createRouter({
navigation: navigation,
history: platform.history,
//history: platform.history,
history: inMemoryHistory,
});
// Populate the `Navigation` with segments to work from
urlRouter.tryRestoreLastUrl();

// We use the timeline to setup the relations between entries
const timeline = new Timeline({
Expand Down
62 changes: 62 additions & 0 deletions shared/lib/in-memory-history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

const { BaseObservableValue } = require('hydrogen-view-sdk');
const assert = require('./assert');

// A Hydrogen History implementation that doesn't touch the URL. This way
// Hydrogen can still route internally while keeping our external facing URL the
// same.
//
// ex. https://hydrogen.element.io/#/session/123/room/!abc:m.org/lightbox/$abc
// and the hash is handling the `#/session/123/room/!abc:m.org/lightbox/$abc`
// part
class InMemoryHistory extends BaseObservableValue {
#hash = '#/session/123/room/!abc:m.org';

constructor(roomId) {
super();

assert(roomId);

// Since we're viewing an archive of a room, let's mimic the URL of the room
// view
this.#hash = `#/session/123/room/${roomId}`;
}

get() {
return this.#hash;
}

/** does not emit */
replaceUrlSilently(url) {
this.#hash = url;
}

/** does not emit */
pushUrlSilently(url) {
this.#hash = url;
}

pushUrl(url) {
this.#hash = url;
}

urlAsPath(url) {
if (url.startsWith('#')) {
return url.substr(1);
} else {
return url;
}
}

pathAsUrl(path) {
return `#${path}`;
}

getLastUrl() {
//throw new Error('Not implemented in InMemoryHistory');
return this.#hash;
}
}

module.exports = InMemoryHistory;