Skip to content

Commit

Permalink
Add permalink highlighting - ?at=$xxx (#123)
Browse files Browse the repository at this point in the history
ex.
```
http://localhost:3050/r/test-room1:my.synapse.server/date/2022/07/28?at=$O9fDg42JoSh9VdcL820FDUS0Gi_CkPt_hrN1pK1fPEY
````

Fix #4

Split out from #121
  • Loading branch information
MadLittleMods authored Nov 3, 2022
1 parent 2dff7ec commit 5bae040
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 39 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@opentelemetry/semantic-conventions": "^1.3.1",
"dompurify": "^2.3.9",
"express": "^4.17.2",
"hydrogen-view-sdk": "npm:@mlm/hydrogen-view-sdk@^0.21.0-scratch",
"hydrogen-view-sdk": "npm:@mlm/hydrogen-view-sdk@^0.22.0-scratch",
"json5": "^2.2.1",
"linkedom": "^0.14.17",
"matrix-public-archive-shared": "file:./shared/",
Expand Down
4 changes: 2 additions & 2 deletions shared/hydrogen-vm-render-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function mountHydrogen() {
const appElement = document.querySelector('#app');

const qs = new URLSearchParams(window?.location?.search);
const scrollStartPosition = qs.get('continue');
const scrollStartEventId = qs.get('at');

const platformConfig = {};
const assetPaths = {};
Expand Down Expand Up @@ -126,7 +126,7 @@ async function mountHydrogen() {
// The timestamp from the URL that was originally visited
dayTimestampFrom: fromTimestamp,
dayTimestampTo: toTimestamp,
scrollStartPosition,
scrollStartEventId,
events,
stateEventMap,
shouldIndex,
Expand Down
19 changes: 4 additions & 15 deletions shared/lib/url-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ class URLCreator {
return `${urlJoin(this._basePath, `${urlPath}`)}${qsToUrlPiece(qs)}`;
}

archiveUrlForDate(roomIdOrAlias, date, { viaServers = [], scrollStartPosition } = {}) {
archiveUrlForDate(roomIdOrAlias, date, { viaServers = [], scrollStartEventId } = {}) {
assert(roomIdOrAlias);
assert(date);

let qs = new URLSearchParams();
[].concat(viaServers).forEach((viaServer) => {
qs.append('via', viaServer);
});
if (scrollStartPosition) {
qs.append('continue', scrollStartPosition);
if (scrollStartEventId) {
qs.append('at', scrollStartEventId);
}

const urlPath = this._getArchiveUrlPathForRoomIdOrAlias(roomIdOrAlias);
Expand All @@ -86,25 +86,14 @@ class URLCreator {
return `${urlJoin(this._basePath, `${urlPath}/date/${urlDate}`)}${qsToUrlPiece(qs)}`;
}

archiveJumpUrlForRoom(
roomIdOrAlias,
{
ts,
dir,
// where the scroll position should continue from ['top'|'bottom']
scrollStartPosition,
}
) {
archiveJumpUrlForRoom(roomIdOrAlias, { ts, dir }) {
assert(roomIdOrAlias);
assert(ts);
assert(dir);

let qs = new URLSearchParams();
qs.append('ts', ts);
qs.append('dir', dir);
if (scrollStartPosition) {
qs.append('continue', scrollStartPosition);
}

const urlPath = this._getArchiveUrlPathForRoomIdOrAlias(roomIdOrAlias);

Expand Down
17 changes: 10 additions & 7 deletions shared/viewmodels/ArchiveRoomViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ArchiveRoomViewModel extends ViewModel {
room,
dayTimestampFrom,
dayTimestampTo,
scrollStartPosition,
scrollStartEventId,
events,
stateEventMap,
shouldIndex,
Expand All @@ -82,7 +82,6 @@ class ArchiveRoomViewModel extends ViewModel {
this._room = room;
this._dayTimestampFrom = dayTimestampFrom;
this._dayTimestampTo = dayTimestampTo;
this._scrollStartPosition = scrollStartPosition === 'top' ? 'top' : 'bottom';
this._currentTopPositionEventEntry = null;
this._matrixPublicArchiveURLCreator = new MatrixPublicArchiveURLCreator(basePath);
this._basePath = basePath;
Expand Down Expand Up @@ -142,9 +141,17 @@ class ArchiveRoomViewModel extends ViewModel {

this._timelineViewModel = {
showJumpDown: false,
setVisibleTileRange: () => {},
setVisibleTileRange() {},
tiles,
// This will cause the event ID to be scrolled into view
get eventIdHighlighted() {
return scrollStartEventId;
},
};
// Set the event highlight
if (scrollStartEventId) {
eventEntriesByEventId[scrollStartEventId].setIsHighlighted(true);
}

// FIXME: Do we have to fake this?
this.rightPanelModel = {
Expand Down Expand Up @@ -250,10 +257,6 @@ class ArchiveRoomViewModel extends ViewModel {
return this._currentTopPositionEventEntry;
}

get scrollStartPosition() {
return this._scrollStartPosition;
}

get shouldShowRightPanel() {
return this._shouldShowRightPanel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class JumpToNextActivitySummaryTileViewModel extends SimpleTile {
{
ts: this.rangeEndTimestamp,
dir: 'f',
scrollStartPosition: 'top',
}
);
}
Expand Down
7 changes: 1 addition & 6 deletions shared/views/ArchiveRoomView.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,7 @@ class ArchiveRoomView extends TemplateView {
t.main({ className: 'ArchiveRoomView_mainArea' }, [
t.view(new RoomHeaderView(vm)),
t.main({ className: 'ArchiveRoomView_mainBody' }, [
t.view(
new TimelineView(vm.timelineViewModel, {
viewClassForTile: customViewClassForTile,
stickToBottom: vm.scrollStartPosition === 'bottom',
})
),
t.view(new TimelineView(vm.timelineViewModel, customViewClassForTile)),
t.view(new DisabledComposerView(vm)),
]),
]),
Expand Down

0 comments on commit 5bae040

Please sign in to comment.