From 96cf8148482ec1631112fecd696249cf05d9e299 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Mon, 1 Nov 2021 03:17:44 -0600 Subject: [PATCH] Add option to disable federation on portal rooms (#362) --- config/bridge.go | 2 ++ example-config.yaml | 4 ++++ portal.go | 19 ++++++++++++------- user.go | 9 +++++++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/config/bridge.go b/config/bridge.go index fec408b..a9d8a1f 100644 --- a/config/bridge.go +++ b/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 { diff --git a/example-config.yaml b/example-config.yaml index 9ce401d..a8b2804 100644 --- a/example-config.yaml +++ b/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: diff --git a/portal.go b/portal.go index ed3265b..787982f 100644 --- a/portal.go +++ b/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 diff --git a/user.go b/user.go index 659cfb4..928bf8d 100644 --- a/user.go +++ b/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)