From 8da5a4e7e2744b4696244835516e4a272e9b7b34 Mon Sep 17 00:00:00 2001
From: TurBoss <j.l.toledano.l@gmail.com>
Date: Thu, 7 Mar 2019 01:19:41 +0100
Subject: [PATCH] Allow to disable join / leave echos

---
 config/config.sample.yaml   |  2 ++
 src/config.ts               |  1 +
 src/matrixeventprocessor.ts | 14 +++++++++++---
 test/test_config.ts         |  2 ++
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/config/config.sample.yaml b/config/config.sample.yaml
index a899c18..ed97ed4 100644
--- a/config/config.sample.yaml
+++ b/config/config.sample.yaml
@@ -27,6 +27,8 @@ bridge:
   # Disable sending of read receipts for Matrix events which have been
   # successfully bridged to Discord.
   disableReadReceipts: false
+  # Disable Join Leave echos from matrix
+  disableJoinLeaveNotifications: false
 # Authentication configuration for the discord bot.
 auth:
   clientID: "12345"
diff --git a/src/config.ts b/src/config.ts
index 0604009..35d82bd 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -54,6 +54,7 @@ class DiscordBridgeConfigBridge {
     public disableReadReceipts: boolean;
     public disableEveryoneMention: boolean = false;
     public disableHereMention: boolean = false;
+    public disableJoinLeaveNotifications: boolean = false;
 }
 
 export class DiscordBridgeConfigDatabase {
diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts
index 1aeae33..a9cd5c7 100644
--- a/src/matrixeventprocessor.ts
+++ b/src/matrixeventprocessor.ts
@@ -85,13 +85,21 @@ export class MatrixEventProcessor {
             const membership = event.content!.membership;
             if (membership === "join"
                 && event.unsigned.prev_content === undefined) {
-                msg += `joined the room`;
+                    if (!this.config.bridge.disableJoinLeaveNotifications) {
+                        msg += `joined the room`;
+                    } else {
+                        return
+                    }
             } else if (membership === "invite") {
                 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`;
             } else if (membership === "leave") {
-                msg += `left the room`;
+                if (!this.config.bridge.disableJoinLeaveNotifications) {
+                    msg += `left the room`;
+                } else {
+                    return
+                }
             } else if (membership === "ban") {
                 msg += `banned \`${event.state_key}\` from the room`;
             }
@@ -302,7 +310,7 @@ export class MatrixEventProcessor {
                 const mxClient = this.bridge.getClientFactory().getClientAs();
                 avatarUrl = mxClient.mxcUrlToHttp(profile.avatar_url, DISCORD_AVATAR_WIDTH, DISCORD_AVATAR_HEIGHT);
             }
-        }
+        }disablePresence
         embed.setAuthor(
             displayName.substr(0, MAX_NAME_LENGTH),
             avatarUrl,
diff --git a/test/test_config.ts b/test/test_config.ts
index ae92324..4df3c6c 100644
--- a/test/test_config.ts
+++ b/test/test_config.ts
@@ -31,6 +31,7 @@ describe("DiscordBridgeConfig.ApplyConfig", () => {
                 disableDiscordMentions: false,
                 disableTypingNotifications: true,
                 enableSelfServiceBridging: false,
+                disableJoinLeaveNotifications: true,
                 homeserverUrl: "blah",
             },
             logging: {
@@ -42,6 +43,7 @@ describe("DiscordBridgeConfig.ApplyConfig", () => {
         expect(config.bridge.disableDiscordMentions).to.be.false;
         expect(config.bridge.disableDeletionForwarding).to.be.true;
         expect(config.bridge.enableSelfServiceBridging).to.be.false;
+        expect(config.brdge.disableJoinLeaveNotifications).to.be.true
         expect(config.logging.console, "warn");
     });
     it("should merge logging.files correctly", () => {
-- 
GitLab