From 3d3c37861c3e25cb20aad6f27dd16f12fe266785 Mon Sep 17 00:00:00 2001
From: Travis Ralston <travpc@gmail.com>
Date: Wed, 21 Feb 2018 20:15:22 -0700
Subject: [PATCH] Auto-accept invites for the bridge bot

---
 src/matrixroomhandler.ts | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/matrixroomhandler.ts b/src/matrixroomhandler.ts
index d45a964..e397a68 100644
--- a/src/matrixroomhandler.ts
+++ b/src/matrixroomhandler.ts
@@ -86,7 +86,15 @@ export class MatrixRoomHandler {
   }
 
   public HandleInvite(event: any) {
-    // Do nothing yet.
+    log.info("MatrixRoomHandler", "Received invite for " + event.state_key + " in room " + event.room_id);
+    if (event.state_key === this.botUserId) {
+      this.bridge.getIntent().getClient().joinRoom(event.room_id).catch(err => {
+        log.error("MatrixRoomHandler", err);
+        setTimeout(() => {
+            this.bridge.getIntent().join(event.room_id).catch(err => log.error("MatrixRoomHandler", err));
+        }, 5000); // Retry the join in 5 seconds if it failed the first time
+      });
+    }
   }
 
   public OnAliasQuery (alias: string, aliasLocalpart: string): Promise<any> {
-- 
GitLab