await the callback in getUserMessagesIn

This is so that the context of failing callbacks are not lost.
We also await during pagination and not after so that if a call to the callback fails, we will not call it again.
This commit is contained in:
gnuxie 2021-10-15 16:42:48 +01:00
parent fefe29e98b
commit 911707ab2e

View File

@ -159,7 +159,9 @@ export async function getMessagesByUserIn(client: MatrixClient, sender: string,
} }
const events = filterEvents(bfMessages['chunk'] || []); const events = filterEvents(bfMessages['chunk'] || []);
// If we are using a glob, there may be no relevant events in this chunk. // If we are using a glob, there may be no relevant events in this chunk.
if (events.length > 0) cb(events); if (events.length > 0) {
await cb(events);
}
} }
} else { } else {
throw new Error(`Internal Error: rooms/initialSync did not return a pagination chunk for ${roomId}, this is not normal and if it is we need to stop using it. See roomInitialSync() for why we are using it.`); throw new Error(`Internal Error: rooms/initialSync did not return a pagination chunk for ${roomId}, this is not normal and if it is we need to stop using it. See roomInitialSync() for why we are using it.`);