From 911707ab2e13c15fcabe0bb70c139110b8b2c3e6 Mon Sep 17 00:00:00 2001 From: gnuxie Date: Fri, 15 Oct 2021 16:42:48 +0100 Subject: [PATCH] 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. --- src/utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 32601f9..83c05bd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -159,7 +159,9 @@ export async function getMessagesByUserIn(client: MatrixClient, sender: string, } const events = filterEvents(bfMessages['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 { 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.`);