浏览代码

Add option to disable federation on portal rooms (#362)

Sumner Evans 3 年之前
父节点
当前提交
96cf814848
共有 4 个文件被更改,包括 25 次插入9 次删除
  1. 2 0
      config/bridge.go
  2. 4 0
      example-config.yaml
  3. 12 7
      portal.go
  4. 7 2
      user.go

+ 2 - 0
config/bridge.go

@@ -70,6 +70,8 @@ type BridgeConfig struct {
 
 	AllowUserInvite bool `yaml:"allow_user_invite"`
 
+	FederateRooms bool `yaml:"federate_rooms"`
+
 	CommandPrefix string `yaml:"command_prefix"`
 
 	ManagementRoomText struct {

+ 4 - 0
example-config.yaml

@@ -165,6 +165,10 @@ bridge:
     # The prefix for commands. Only required in non-management rooms.
     command_prefix: "!wa"
 
+    # Whether or not created rooms should have federation enabled.
+    # If false, created portal rooms will never be federated.
+    federate_rooms: true
+
     # Messages sent upon joining a management room.
     # Markdown is supported. The defaults are listed below.
     management_room_text:

+ 12 - 7
portal.go

@@ -1311,14 +1311,19 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo) e
 		}
 	}
 
+	creationContent := make(map[string]interface{})
+	if !portal.bridge.Config.Bridge.FederateRooms {
+		creationContent["m.federate"] = false
+	}
 	resp, err := intent.CreateRoom(&mautrix.ReqCreateRoom{
-		Visibility:   "private",
-		Name:         portal.Name,
-		Topic:        portal.Topic,
-		Invite:       invite,
-		Preset:       "private_chat",
-		IsDirect:     portal.IsPrivateChat(),
-		InitialState: initialState,
+		Visibility:      "private",
+		Name:            portal.Name,
+		Topic:           portal.Topic,
+		Invite:          invite,
+		Preset:          "private_chat",
+		IsDirect:        portal.IsPrivateChat(),
+		InitialState:    initialState,
+		CreationContent: creationContent,
 	})
 	if err != nil {
 		return err

+ 7 - 2
user.go

@@ -181,9 +181,14 @@ func (user *User) GetManagementRoom() id.RoomID {
 		if len(user.ManagementRoom) > 0 {
 			return user.ManagementRoom
 		}
+		creationContent := make(map[string]interface{})
+		if !user.bridge.Config.Bridge.FederateRooms {
+			creationContent["m.federate"] = false
+		}
 		resp, err := user.bridge.Bot.CreateRoom(&mautrix.ReqCreateRoom{
-			Topic:    "WhatsApp bridge notices",
-			IsDirect: true,
+			Topic:           "WhatsApp bridge notices",
+			IsDirect:        true,
+			CreationContent: creationContent,
 		})
 		if err != nil {
 			user.log.Errorln("Failed to auto-create management room:", err)