From 122fbb99a46acecda56012f6bba6f49ba079771d Mon Sep 17 00:00:00 2001 From: Florent F <florent.fayolle69@gmail.com> Date: Sat, 4 Jan 2020 21:22:13 +0100 Subject: [PATCH] Add disableInviteNotifications option to drop invitations notifs --- config/config.sample.yaml | 2 ++ config/config.schema.yaml | 4 ++++ src/config.ts | 1 + src/matrixeventprocessor.ts | 3 ++- test/test_config.ts | 4 ++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/config.sample.yaml b/config/config.sample.yaml index d000b2d..554e511 100644 --- a/config/config.sample.yaml +++ b/config/config.sample.yaml @@ -29,6 +29,8 @@ bridge: disableReadReceipts: false # Disable Join Leave echos from matrix disableJoinLeaveNotifications: false + # Disable Invite echos from matrix + disableInviteNotifications: false # Authentication configuration for the discord bot. auth: # This MUST be a string (wrapped in quotes) diff --git a/config/config.schema.yaml b/config/config.schema.yaml index 7439ef2..860f131 100644 --- a/config/config.schema.yaml +++ b/config/config.schema.yaml @@ -22,6 +22,10 @@ properties: type: "boolean" disableReadReceipts: type: "boolean" + disableJoinLeaveNotifications: + type: "boolean" + disableInviteNotifications: + type: "boolean" auth: type: "object" required: ["botToken", "clientID"] diff --git a/src/config.ts b/src/config.ts index 9d966b5..de777b8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -90,6 +90,7 @@ class DiscordBridgeConfigBridge { public disableEveryoneMention: boolean = false; public disableHereMention: boolean = false; public disableJoinLeaveNotifications: boolean = false; + public disableInviteNotifications: boolean = false; public enableMetrics: boolean = false; } diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 5e6428a..cb5f87a 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -231,6 +231,7 @@ export class MatrixEventProcessor { let msg = `\`${event.sender}\` `; const allowJoinLeave = !this.config.bridge.disableJoinLeaveNotifications; + const allowInvite = !this.config.bridge.disableInviteNotifications; if (event.type === "m.room.name") { msg += `set the name to \`${event.content!.name}\``; @@ -255,7 +256,7 @@ export class MatrixEventProcessor { } if (membership === "join" && isNewJoin && allowJoinLeave) { msg += "joined the room"; - } else if (membership === "invite") { + } else if (membership === "invite" && allowInvite) { msg += `invited \`${event.state_key}\` to the room`; } else if (membership === "leave" && event.state_key !== event.sender) { msg += `kicked \`${event.state_key}\` from the room`; diff --git a/test/test_config.ts b/test/test_config.ts index badb662..270eb08 100644 --- a/test/test_config.ts +++ b/test/test_config.ts @@ -30,6 +30,7 @@ describe("DiscordBridgeConfig.applyConfig", () => { disableDeletionForwarding: true, disableDiscordMentions: false, disableJoinLeaveNotifications: true, + disableInviteNotifications: true, disableTypingNotifications: true, enableSelfServiceBridging: false, homeserverUrl: "blah", @@ -44,6 +45,7 @@ describe("DiscordBridgeConfig.applyConfig", () => { expect(config.bridge.disableDeletionForwarding).to.be.true; expect(config.bridge.enableSelfServiceBridging).to.be.false; expect(config.bridge.disableJoinLeaveNotifications).to.be.true; + expect(config.bridge.disableInviteNotifications).to.be.true; expect(config.logging.console).to.equal("warn"); }); it("should merge environment overrides correctly", () => { @@ -61,9 +63,11 @@ describe("DiscordBridgeConfig.applyConfig", () => { config.applyEnvironmentOverrides({ APPSERVICE_DISCORD_BRIDGE_DISABLE_DELETION_FORWARDING: false, APPSERVICE_DISCORD_BRIDGE_DISABLE_JOIN_LEAVE_NOTIFICATIONS: true, + APPSERVICE_DISCORD_BRIDGE_DISABLE_INVITE_NOTIFICATIONS: true, APPSERVICE_DISCORD_LOGGING_CONSOLE: "debug", }); expect(config.bridge.disableJoinLeaveNotifications).to.be.true; + expect(config.bridge.disableInviteNotifications).to.be.true; expect(config.bridge.disableDeletionForwarding).to.be.false; expect(config.bridge.disableDiscordMentions).to.be.false; expect(config.bridge.homeserverUrl).to.equal("blah"); -- GitLab