Skip to content

Commit

Permalink
Add permalink highlighting
Browse files Browse the repository at this point in the history
Fix #4
  • Loading branch information
MadLittleMods committed Nov 3, 2022
1 parent 2dff7ec commit 78a1e0b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 deletions.
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 78a1e0b

Please sign in to comment.