From 78a1e0b805c6c85a69d95332b46aeb095f6663db Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 3 Nov 2022 04:16:56 -0500 Subject: [PATCH] Add permalink highlighting Fix https://github.com/matrix-org/matrix-public-archive/issues/4 --- shared/hydrogen-vm-render-script.js | 4 ++-- shared/lib/url-creator.js | 19 ++++--------------- shared/viewmodels/ArchiveRoomViewModel.js | 17 ++++++++++------- .../JumpToNextActivitySummaryTileViewModel.js | 1 - shared/views/ArchiveRoomView.js | 7 +------ 5 files changed, 17 insertions(+), 31 deletions(-) diff --git a/shared/hydrogen-vm-render-script.js b/shared/hydrogen-vm-render-script.js index 91be577e..aa9a6879 100644 --- a/shared/hydrogen-vm-render-script.js +++ b/shared/hydrogen-vm-render-script.js @@ -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 = {}; @@ -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, diff --git a/shared/lib/url-creator.js b/shared/lib/url-creator.js index c34b94e8..6adefa0e 100644 --- a/shared/lib/url-creator.js +++ b/shared/lib/url-creator.js @@ -65,7 +65,7 @@ class URLCreator { return `${urlJoin(this._basePath, `${urlPath}`)}${qsToUrlPiece(qs)}`; } - archiveUrlForDate(roomIdOrAlias, date, { viaServers = [], scrollStartPosition } = {}) { + archiveUrlForDate(roomIdOrAlias, date, { viaServers = [], scrollStartEventId } = {}) { assert(roomIdOrAlias); assert(date); @@ -73,8 +73,8 @@ class URLCreator { [].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); @@ -86,15 +86,7 @@ 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); @@ -102,9 +94,6 @@ class URLCreator { let qs = new URLSearchParams(); qs.append('ts', ts); qs.append('dir', dir); - if (scrollStartPosition) { - qs.append('continue', scrollStartPosition); - } const urlPath = this._getArchiveUrlPathForRoomIdOrAlias(roomIdOrAlias); diff --git a/shared/viewmodels/ArchiveRoomViewModel.js b/shared/viewmodels/ArchiveRoomViewModel.js index ff56d0dc..a6ef028c 100644 --- a/shared/viewmodels/ArchiveRoomViewModel.js +++ b/shared/viewmodels/ArchiveRoomViewModel.js @@ -64,7 +64,7 @@ class ArchiveRoomViewModel extends ViewModel { room, dayTimestampFrom, dayTimestampTo, - scrollStartPosition, + scrollStartEventId, events, stateEventMap, shouldIndex, @@ -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; @@ -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 = { @@ -250,10 +257,6 @@ class ArchiveRoomViewModel extends ViewModel { return this._currentTopPositionEventEntry; } - get scrollStartPosition() { - return this._scrollStartPosition; - } - get shouldShowRightPanel() { return this._shouldShowRightPanel; } diff --git a/shared/viewmodels/JumpToNextActivitySummaryTileViewModel.js b/shared/viewmodels/JumpToNextActivitySummaryTileViewModel.js index 3cf7f4e5..5b2c9034 100644 --- a/shared/viewmodels/JumpToNextActivitySummaryTileViewModel.js +++ b/shared/viewmodels/JumpToNextActivitySummaryTileViewModel.js @@ -38,7 +38,6 @@ class JumpToNextActivitySummaryTileViewModel extends SimpleTile { { ts: this.rangeEndTimestamp, dir: 'f', - scrollStartPosition: 'top', } ); } diff --git a/shared/views/ArchiveRoomView.js b/shared/views/ArchiveRoomView.js index 85c27ea0..3a4c0cb3 100644 --- a/shared/views/ArchiveRoomView.js +++ b/shared/views/ArchiveRoomView.js @@ -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)), ]), ]),