From fc1b336e63d622831bd5cb4db00a7a955e38ec86 Mon Sep 17 00:00:00 2001
From: Andrew Morgan <andrew@amorgan.xyz>
Date: Tue, 12 Sep 2017 18:05:41 +0000
Subject: [PATCH] Add config option to specify default directory listing

This commit adds a new section and option in config.yaml for rooms and whether
they should be shown in the HS' public directory listing by default.

The default behavior is to show them.
---
 config/config.sample.yaml | 2 ++
 config/config.schema.yaml | 6 ++++++
 src/config.ts             | 5 +++++
 src/matrixroomhandler.ts  | 2 +-
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/config/config.sample.yaml b/config/config.sample.yaml
index 16c4883..afed906 100644
--- a/config/config.sample.yaml
+++ b/config/config.sample.yaml
@@ -9,3 +9,5 @@ logging:
   level: "warn" #silly, verbose, info, http, warn, error
 database:
   filename: "discord.db"
+room:
+  defaultVisibility: "public"
diff --git a/config/config.schema.yaml b/config/config.schema.yaml
index 3a1f19f..a0755b9 100644
--- a/config/config.schema.yaml
+++ b/config/config.schema.yaml
@@ -32,3 +32,9 @@ properties:
         properties:
           filename:
             type: "string"
+    room:
+        type: "object"
+        required: ["defaultVisibility"]
+        properties:
+          defaultVisibility:
+            type: "string"
diff --git a/src/config.ts b/src/config.ts
index 124aebd..bcacbfc 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -5,6 +5,7 @@ export class DiscordBridgeConfig {
   public auth: DiscordBridgeConfigAuth;
   public logging: DiscordBridgeConfigLogging;
   public database: DiscordBridgeConfigDatabase;
+  public room: DiscordBridgeConfigRoom;
 }
 
 class DiscordBridgeConfigBridge {
@@ -24,3 +25,7 @@ export class DiscordBridgeConfigAuth {
 class DiscordBridgeConfigLogging {
   public level: string;
 }
+
+class DiscordBridgeConfigRoom {
+  public defaultVisibility: string;
+}
diff --git a/src/matrixroomhandler.ts b/src/matrixroomhandler.ts
index 9c2ee74..d45a964 100644
--- a/src/matrixroomhandler.ts
+++ b/src/matrixroomhandler.ts
@@ -175,7 +175,7 @@ export class MatrixRoomHandler {
     remote.set("update_name", true);
     remote.set("update_topic", true);
     const creationOpts = {
-      visibility: "public",
+      visibility: this.config.room.defaultVisibility,
       room_alias_name: alias,
       name: `[Discord] ${channel.guild.name} #${channel.name}`,
       topic: channel.topic ? channel.topic : "",
-- 
GitLab