Skip to content

Commit

Permalink
bridgev2/config: add more granular control over room tags
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Nov 13, 2024
1 parent b22764a commit 3f9a637
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bridgev2/bridgeconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.mau.fi/zeroconfig"
"gopkg.in/yaml.v3"

"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/mediaproxy"
)

Expand Down Expand Up @@ -65,7 +66,7 @@ type BridgeConfig struct {
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
BridgeMatrixLeave bool `yaml:"bridge_matrix_leave"`
TagOnlyOnCreate bool `yaml:"tag_only_on_create"`
EnableTagBridging bool `yaml:"enable_tag_bridging"`
OnlyBridgeTags []event.RoomTag `yaml:"only_bridge_tags"`
MuteOnlyOnCreate bool `yaml:"mute_only_on_create"`
OutgoingMessageReID bool `yaml:"outgoing_message_re_id"`
CleanupOnLogout CleanupOnLogouts `yaml:"cleanup_on_logout"`
Expand Down
2 changes: 1 addition & 1 deletion bridgev2/bridgeconfig/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func doUpgrade(helper up.Helper) {
helper.Copy(up.Bool, "bridge", "resend_bridge_info")
helper.Copy(up.Bool, "bridge", "bridge_matrix_leave")
helper.Copy(up.Bool, "bridge", "tag_only_on_create")
helper.Copy(up.Bool, "bridge", "enable_tag_bridging")
helper.Copy(up.List, "bridge", "only_bridge_tags")
helper.Copy(up.Bool, "bridge", "mute_only_on_create")
helper.Copy(up.Bool, "bridge", "cleanup_on_logout", "enabled")
helper.Copy(up.Str, "bridge", "cleanup_on_logout", "manual", "private")
Expand Down
4 changes: 2 additions & 2 deletions bridgev2/matrix/mxmain/example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ bridge:
# Should room tags only be synced when creating the portal? Tags mean things like favorite/pin and archive/low priority.
# Tags currently can't be synced back to the remote network, so a continuous sync means tagging from Matrix will be undone.
tag_only_on_create: true
# Should room tags be synced at all?
enable_tag_bridging: true
# List of tags to allow bridging. If empty, no tags will be bridged.
only_bridge_tags: [m.favourite, m.lowpriority]
# Should room mute status only be synced when creating the portal?
# Like tags, mutes can't currently be synced back to the remote network.
mute_only_on_create: true
Expand Down
6 changes: 5 additions & 1 deletion bridgev2/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3269,7 +3269,11 @@ func (portal *Portal) updateUserLocalInfo(ctx context.Context, info *UserLocalPo
zerolog.Ctx(ctx).Err(err).Msg("Failed to mute room")
}
}
if info.Tag != nil && portal.Bridge.Config.EnableTagBridging && (didJustCreate || !portal.Bridge.Config.TagOnlyOnCreate) && (!didJustCreate || *info.Tag != "") {
if info.Tag != nil &&
len(portal.Bridge.Config.OnlyBridgeTags) > 0 &&
(*info.Tag == "" || slices.Contains(portal.Bridge.Config.OnlyBridgeTags, *info.Tag)) &&
(didJustCreate || !portal.Bridge.Config.TagOnlyOnCreate) &&
(!didJustCreate || *info.Tag != "") {
err := dp.TagRoom(ctx, portal.MXID, *info.Tag, *info.Tag != "")
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Failed to tag room")
Expand Down

0 comments on commit 3f9a637

Please sign in to comment.