Fix last event in day not being shown
This commit is contained in:
parent
2153fa4852
commit
c34ed9ea0e
|
@ -59,7 +59,7 @@ async function fetchEventsFromTimestampBackwards(accessToken, roomId, ts, limit)
|
||||||
// Add filter={"lazy_load_members":true,"include_redundant_members":true} to get member state events included
|
// Add filter={"lazy_load_members":true,"include_redundant_members":true} to get member state events included
|
||||||
const messagesEndpoint = urlJoin(
|
const messagesEndpoint = urlJoin(
|
||||||
matrixServerUrl,
|
matrixServerUrl,
|
||||||
`_matrix/client/r0/rooms/${roomId}/messages?dir=b&from=${contextResData.start}&limit=${limit}&filter={"lazy_load_members":true,"include_redundant_members":true}`
|
`_matrix/client/r0/rooms/${roomId}/messages?dir=b&from=${contextResData.end}&limit=${limit}&filter={"lazy_load_members":true,"include_redundant_members":true}`
|
||||||
);
|
);
|
||||||
const messageResData = await fetchEndpointAsJson(messagesEndpoint, {
|
const messageResData = await fetchEndpointAsJson(messagesEndpoint, {
|
||||||
accessToken,
|
accessToken,
|
||||||
|
@ -86,6 +86,8 @@ async function fetchEventsInRange(accessToken, roomId, startTs, endTs, limit) {
|
||||||
assert(endTs);
|
assert(endTs);
|
||||||
assert(limit);
|
assert(limit);
|
||||||
|
|
||||||
|
//console.log('fetchEventsInRange', startTs, endTs);
|
||||||
|
|
||||||
// Fetch events from endTs and before
|
// Fetch events from endTs and before
|
||||||
const { events, stateEventMap } = await fetchEventsFromTimestampBackwards(
|
const { events, stateEventMap } = await fetchEventsFromTimestampBackwards(
|
||||||
accessToken,
|
accessToken,
|
||||||
|
@ -94,6 +96,8 @@ async function fetchEventsInRange(accessToken, roomId, startTs, endTs, limit) {
|
||||||
limit
|
limit
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//console.log('events', events.length);
|
||||||
|
|
||||||
let eventsInRange = events;
|
let eventsInRange = events;
|
||||||
// `events` are in reverse-chronological order.
|
// `events` are in reverse-chronological order.
|
||||||
// We only need to filter if the oldest message is before startTs
|
// We only need to filter if the oldest message is before startTs
|
||||||
|
@ -113,6 +117,8 @@ async function fetchEventsInRange(accessToken, roomId, startTs, endTs, limit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//console.log('eventsInRange', eventsInRange.length);
|
||||||
|
|
||||||
const chronologicalEventsInRange = eventsInRange.reverse();
|
const chronologicalEventsInRange = eventsInRange.reverse();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -145,6 +145,68 @@ describe('matrix-public-archive', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows all events in a given day', async () => {
|
||||||
|
try {
|
||||||
|
const client = await getTestClientForHs(testMatrixServerUrl1);
|
||||||
|
const roomId = await createTestRoom(client);
|
||||||
|
|
||||||
|
const archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(roomId, new Date());
|
||||||
|
// Just render the page initially so that the archiver user is already joined to the page.
|
||||||
|
// We don't want their join event masking the one-off problem where we're missing the latest message in the room.
|
||||||
|
await fetchEndpointAsText(archiveUrl);
|
||||||
|
|
||||||
|
const messageTextList = [
|
||||||
|
`Amontons' First Law: The force of friction is directly proportional to the applied load.`,
|
||||||
|
`Amontons' Second Law: The force of friction is independent of the apparent area of contact.`,
|
||||||
|
// We're aiming for this to be the last message in the room
|
||||||
|
`Coulomb's Law of Friction: Kinetic friction is independent of the sliding velocity.`,
|
||||||
|
];
|
||||||
|
|
||||||
|
const eventIds = [];
|
||||||
|
for (const messageText of messageTextList) {
|
||||||
|
const eventId = await client.sendMessage(roomId, {
|
||||||
|
msgtype: 'm.text',
|
||||||
|
body: messageText,
|
||||||
|
});
|
||||||
|
eventIds.push(eventId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanity check that we actually sent some messages
|
||||||
|
assert.strictEqual(eventIds.length, 3);
|
||||||
|
|
||||||
|
if (interactive) {
|
||||||
|
console.log('Interactive URL for test', archiveUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
const archivePageHtml = await fetchEndpointAsText(archiveUrl);
|
||||||
|
|
||||||
|
const dom = parseHTML(archivePageHtml);
|
||||||
|
|
||||||
|
// Make sure the messages are visible
|
||||||
|
for (let i = 0; i < eventIds.length; i++) {
|
||||||
|
const eventId = eventIds[i];
|
||||||
|
const eventText = messageTextList[i];
|
||||||
|
assert.match(
|
||||||
|
dom.document.querySelector(`[data-event-id="${eventId}"]`).outerHTML,
|
||||||
|
new RegExp(`.*${escapeStringRegexp(eventText)}.*`)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (err.body) {
|
||||||
|
// FIXME: Remove this try/catch once the matrix-bot-sdk no longer throws
|
||||||
|
// huge response objects as errors, see
|
||||||
|
// https://github.com/turt2live/matrix-bot-sdk/pull/158
|
||||||
|
throw new Error(
|
||||||
|
`Error occured in matrix-bot-sdk (this new error is to stop it from logging the huge response) statusCode=${
|
||||||
|
err.statusCode
|
||||||
|
} body=${JSON.stringify(err.body)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line max-statements
|
// eslint-disable-next-line max-statements
|
||||||
it('can render diverse messages', async () => {
|
it('can render diverse messages', async () => {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue