Fix time selector showing when less than the page limit of messages (#213)

Fix https://github.com/matrix-org/matrix-public-archive/issues/211
This commit is contained in:
Eric Eastwood 2023-05-04 20:50:43 -05:00 committed by GitHub
parent 9b067f8637
commit b10884505a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 7 deletions

View File

@ -922,8 +922,9 @@ router.get(
stateEventMap, stateEventMap,
shouldIndex, shouldIndex,
config: { config: {
basePath: basePath, basePath,
matrixServerUrl: matrixServerUrl, matrixServerUrl,
archiveMessageLimit,
}, },
}, },
abortSignal: req.abortSignal, abortSignal: req.abortSignal,

View File

@ -31,6 +31,7 @@ const config = window.matrixPublicArchiveContext.config;
assert(config); assert(config);
assert(config.matrixServerUrl); assert(config.matrixServerUrl);
assert(config.basePath); assert(config.basePath);
assert(config.archiveMessageLimit);
function addSupportClasses() { function addSupportClasses() {
const input = document.createElement('input'); const input = document.createElement('input');
@ -108,6 +109,7 @@ async function mountHydrogen() {
history: archiveHistory, history: archiveHistory,
// Our options // Our options
homeserverUrl: config.matrixServerUrl, homeserverUrl: config.matrixServerUrl,
archiveMessageLimit: config.archiveMessageLimit,
room, room,
// The timestamp from the URL that was originally visited // The timestamp from the URL that was originally visited
dayTimestampTo: toTimestamp, dayTimestampTo: toTimestamp,

View File

@ -67,6 +67,7 @@ class ArchiveRoomViewModel extends ViewModel {
super(options); super(options);
const { const {
homeserverUrl, homeserverUrl,
archiveMessageLimit,
room, room,
dayTimestampTo, dayTimestampTo,
precisionFromUrl, precisionFromUrl,
@ -77,6 +78,7 @@ class ArchiveRoomViewModel extends ViewModel {
basePath, basePath,
} = options; } = options;
assert(homeserverUrl); assert(homeserverUrl);
assert(archiveMessageLimit);
assert(room); assert(room);
assert(dayTimestampTo); assert(dayTimestampTo);
assert(Object.values(TIME_PRECISION_VALUES).includes(precisionFromUrl)); assert(Object.values(TIME_PRECISION_VALUES).includes(precisionFromUrl));
@ -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 // 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. // more sense. But only if they are worried about time precision in the URL already.
(precisionFromUrl !== TIME_PRECISION_VALUES.none && !events.length) || (precisionFromUrl !== TIME_PRECISION_VALUES.none && !events.length) ||
// Only show the time selector when we're showing events all from the same day. // Only show the time selector when we're showing events all from the same day and
(events.length && // there are more events than the limit
(events.length > archiveMessageLimit &&
areTimestampsFromSameUtcDay(timelineRangeStartTimestamp, timelineRangeEndTimestamp)); areTimestampsFromSameUtcDay(timelineRangeStartTimestamp, timelineRangeEndTimestamp));
this._timeSelectorViewModel = new TimeSelectorViewModel({ this._timeSelectorViewModel = new TimeSelectorViewModel({

View File

@ -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 () => { 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 // Set this low so we don't have to deal with many messages in the tests But
config.set('archiveMessageLimit', 5); // 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); 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); const roomId = await createTestRoom(client);
await createMessagesInRoom({ await createMessagesInRoom({
client, client,
roomId, roomId,
// This should be lesser than the `archiveMessageLimit` // This should be lesser than the `archiveMessageLimit`
numMessages: 3, numMessages: 1,
prefix: `foo`, prefix: `foo`,
timestamp: archiveDate.getTime(), timestamp: archiveDate.getTime(),
// Just spread things out a bit so the event times are more obvious // Just spread things out a bit so the event times are more obvious