Skip to content

Commit

Permalink
Fix time selector showing when less than the page limit of messages (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods authored May 5, 2023
1 parent 9b067f8 commit b108845
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 3 additions & 2 deletions server/routes/room-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,9 @@ router.get(
stateEventMap,
shouldIndex,
config: {
basePath: basePath,
matrixServerUrl: matrixServerUrl,
basePath,
matrixServerUrl,
archiveMessageLimit,
},
},
abortSignal: req.abortSignal,
Expand Down
2 changes: 2 additions & 0 deletions shared/hydrogen-vm-render-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const config = window.matrixPublicArchiveContext.config;
assert(config);
assert(config.matrixServerUrl);
assert(config.basePath);
assert(config.archiveMessageLimit);

function addSupportClasses() {
const input = document.createElement('input');
Expand Down Expand Up @@ -108,6 +109,7 @@ async function mountHydrogen() {
history: archiveHistory,
// Our options
homeserverUrl: config.matrixServerUrl,
archiveMessageLimit: config.archiveMessageLimit,
room,
// The timestamp from the URL that was originally visited
dayTimestampTo: toTimestamp,
Expand Down
7 changes: 5 additions & 2 deletions shared/viewmodels/ArchiveRoomViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ArchiveRoomViewModel extends ViewModel {
super(options);
const {
homeserverUrl,
archiveMessageLimit,
room,
dayTimestampTo,
precisionFromUrl,
Expand All @@ -77,6 +78,7 @@ class ArchiveRoomViewModel extends ViewModel {
basePath,
} = options;
assert(homeserverUrl);
assert(archiveMessageLimit);
assert(room);
assert(dayTimestampTo);
assert(Object.values(TIME_PRECISION_VALUES).includes(precisionFromUrl));
Expand Down Expand Up @@ -146,8 +148,9 @@ class ArchiveRoomViewModel extends ViewModel {
// before the room was created and we will let them pick a new time that might make
// more sense. But only if they are worried about time precision in the URL already.
(precisionFromUrl !== TIME_PRECISION_VALUES.none && !events.length) ||
// Only show the time selector when we're showing events all from the same day.
(events.length &&
// Only show the time selector when we're showing events all from the same day and
// there are more events than the limit
(events.length > archiveMessageLimit &&
areTimestampsFromSameUtcDay(timelineRangeStartTimestamp, timelineRangeEndTimestamp));

this._timeSelectorViewModel = new TimeSelectorViewModel({
Expand Down
12 changes: 9 additions & 3 deletions test/e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,17 +697,23 @@ describe('matrix-public-archive', () => {
});

it('does not show time selector when all events from the same day but not over the limit', async () => {
// Set this low so we don't have to deal with many messages in the tests
config.set('archiveMessageLimit', 5);
// Set this low so we don't have to deal with many messages in the tests But
// high enough to encompass all of the primoridial room creation events +
// whatever messages we send in the room for this test.
config.set('archiveMessageLimit', 15);

const client = await getTestClientForHs(testMatrixServerUrl1);
// FIXME: This test is flawed and needs MSC3997 to timestamp massage the
// `/createRoom` events otherwise the `areTimestampsFromSameUtcDay(...)` will
// always be false because the create room events are from today vs the
// timestamp massaged messages we send below.
const roomId = await createTestRoom(client);

await createMessagesInRoom({
client,
roomId,
// This should be lesser than the `archiveMessageLimit`
numMessages: 3,
numMessages: 1,
prefix: `foo`,
timestamp: archiveDate.getTime(),
// Just spread things out a bit so the event times are more obvious
Expand Down

0 comments on commit b108845

Please sign in to comment.