From 17163dde92532392d038fe22a1396403e5155619 Mon Sep 17 00:00:00 2001
From: Jonas Herzig <me@johni0702.de>
Date: Fri, 28 Dec 2018 12:25:24 +0100
Subject: [PATCH] Send read receipt for successfully bridged Matrix event
 (closes #326)

---
 config/config.sample.yaml | 3 +++
 config/config.schema.yaml | 2 ++
 src/bot.ts                | 6 ++++++
 src/config.ts             | 1 +
 4 files changed, 12 insertions(+)

diff --git a/config/config.sample.yaml b/config/config.sample.yaml
index 146668d..a899c18 100644
--- a/config/config.sample.yaml
+++ b/config/config.sample.yaml
@@ -24,6 +24,9 @@ bridge:
   # Enable users to bridge rooms using !discord commands. See
   # https://t2bot.io/discord for instructions.
   enableSelfServiceBridging: false
+  # Disable sending of read receipts for Matrix events which have been
+  # successfully bridged to Discord.
+  disableReadReceipts: false
 # Authentication configuration for the discord bot.
 auth:
   clientID: "12345"
diff --git a/config/config.schema.yaml b/config/config.schema.yaml
index 17b816c..9a35f4b 100644
--- a/config/config.schema.yaml
+++ b/config/config.schema.yaml
@@ -20,6 +20,8 @@ properties:
             type: "boolean"
           enableSelfServiceBridging:
             type: "boolean"
+          disableReadReceipts:
+            type: "boolean"
     auth:
         type: "object"
         required: ["botToken", "clientID"]
diff --git a/src/bot.ts b/src/bot.ts
index 5c151ed..43e3e7c 100644
--- a/src/bot.ts
+++ b/src/bot.ts
@@ -321,6 +321,9 @@ export class DiscordBot {
             evt.ChannelId = channel.id;
             await this.store.Insert(evt);
         });
+        if (!this.config.bridge.disableReadReceipts) {
+            await this.bridge.getIntent().sendReadReceipt(event.room_id, event.event_id)
+        }
     }
 
     public async ProcessMatrixMsgEvent(event: IMatrixEvent, guildId: string, channelId: string): Promise<void> {
@@ -393,6 +396,9 @@ export class DiscordBot {
             evt.ChannelId = channelId;
             await this.store.Insert(evt);
         });
+        if (!this.config.bridge.disableReadReceipts) {
+            await this.bridge.getIntent().sendReadReceipt(event.room_id, event.event_id)
+        }
         return;
     }
 
diff --git a/src/config.ts b/src/config.ts
index c5dfb88..a94c720 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -35,6 +35,7 @@ class DiscordBridgeConfigBridge {
     public disableDiscordMentions: boolean;
     public disableDeletionForwarding: boolean;
     public enableSelfServiceBridging: boolean;
+    public disableReadReceipts: boolean;
     public disableEveryoneMention: boolean = false;
     public disableHereMention: boolean = false;
 }
-- 
GitLab