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

This commit is contained in:
Sumner Evans 2021-11-01 03:17:44 -06:00 committed by GitHub
parent 79f51af06e
commit 96cf814848
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 9 deletions

View file

@ -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 {

View file

@ -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:

View file

@ -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

View file

@ -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)