From b3f67b3b2e6b10f8c779f5b15d5841f5b2791f47 Mon Sep 17 00:00:00 2001 From: Will Hunt <will@half-shot.uk> Date: Wed, 24 Oct 2018 21:02:38 +0100 Subject: [PATCH] Sneaky check to see if we are joined by sending a RR --- src/matrixroomhandler.ts | 14 +++++++++++++- test/test_matrixroomhandler.ts | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/matrixroomhandler.ts b/src/matrixroomhandler.ts index 4107f20..e777253 100644 --- a/src/matrixroomhandler.ts +++ b/src/matrixroomhandler.ts @@ -120,7 +120,10 @@ export class MatrixRoomHandler { return this.discord.ProcessMatrixRedact(event); } else if (event.type === "m.room.message" || event.type === "m.sticker") { log.verbose(`Got ${event.type} event`); - if (event.type === "m.room.message" && event.content.body && event.content.body.startsWith("!discord")) { + const isBotCommand = event.type === "m.room.message" && + event.content.body && + event.content.body.startsWith("!discord"); + if (isBotCommand) { return this.ProcessCommand(event, context); } else if (context.rooms.remote) { const srvChanPair = context.rooms.remote.roomId.substr("_discord".length).split("_", ROOM_NAME_PARTS); @@ -168,6 +171,15 @@ export class MatrixRoomHandler { } public async ProcessCommand(event: any, context: any) { + const intent = this.bridge.getIntent(); + // Due to #257 we need to check if we are joined. + try { + await intent.getClient().sendReadReceipt(event.event_id); + } catch (ex) { + log.warn("Couldn't send a read reciept into the room:", ex, ". Ignoring command."); + return; + } + if (!this.config.bridge.enableSelfServiceBridging) { // We can do this here because the only commands we support are self-service bridging return this.bridge.getIntent().sendMessage(event.room_id, { diff --git a/test/test_matrixroomhandler.ts b/test/test_matrixroomhandler.ts index 0bfefe5..31a0c45 100644 --- a/test/test_matrixroomhandler.ts +++ b/test/test_matrixroomhandler.ts @@ -147,6 +147,9 @@ function createRH(opts: any = {}) { setRoomDirectoryVisibilityAppService: () => { return Promise.resolve(); }, + sendReadReceipt: () => { + return Promise.resolve(); + }, }; const provisioner = { AskBridgePermission: () => { -- GitLab