Add hacky option to mute all guild channels on create

This commit is contained in:
Tulir Asokan
2023-01-20 15:07:18 +02:00
parent da9f169333
commit e2bd89bd97
5 changed files with 33 additions and 6 deletions

View File

@@ -42,6 +42,7 @@ type BridgeConfig struct {
MessageErrorNotices bool `yaml:"message_error_notices"`
RestrictedRooms bool `yaml:"restricted_rooms"`
AutojoinThreadOnOpen bool `yaml:"autojoin_thread_on_open"`
MuteChannelsOnCreate bool `yaml:"mute_channels_on_create"`
SyncDirectChatList bool `yaml:"sync_direct_chat_list"`
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
DeletePortalOnChannelDelete bool `yaml:"delete_portal_on_channel_delete"`

View File

@@ -37,6 +37,7 @@ func DoUpgrade(helper *up.Helper) {
helper.Copy(up.Bool, "bridge", "message_error_notices")
helper.Copy(up.Bool, "bridge", "restricted_rooms")
helper.Copy(up.Bool, "bridge", "autojoin_thread_on_open")
helper.Copy(up.Bool, "bridge", "mute_channels_on_create")
helper.Copy(up.Bool, "bridge", "sync_direct_chat_list")
helper.Copy(up.Bool, "bridge", "resend_bridge_info")
helper.Copy(up.Bool, "bridge", "delete_portal_on_channel_delete")

View File

@@ -115,6 +115,9 @@ bridge:
# Should the bridge automatically join the user to threads on Discord when the thread is opened on Matrix?
# This only works with clients that support thread read receipts (MSC3771 added in Matrix v1.4).
autojoin_thread_on_open: true
# Should guild channels be muted when the portal is created? This only meant for single-user instances,
# it won't mute it for all users if there are multiple Matrix users in the same Discord guild.
mute_channels_on_create: false
# Should the bridge update the m.direct account data event when double puppeting is enabled.
# Note that updating the m.direct event is not atomic (except with mautrix-asmux)
# and is therefore prone to race conditions.

View File

@@ -178,6 +178,9 @@ func (puppet *Puppet) IntentFor(portal *Portal) *appservice.IntentAPI {
}
func (puppet *Puppet) CustomIntent() *appservice.IntentAPI {
if puppet == nil {
return nil
}
return puppet.customIntent
}

31
user.go
View File

@@ -22,6 +22,7 @@ import (
"maunium.net/go/mautrix/bridge/status"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/pushrules"
"go.mau.fi/mautrix-discord/database"
)
@@ -392,17 +393,35 @@ func (user *User) ViewingChannel(portal *Portal) bool {
return false
}
func (user *User) mutePortal(intent *appservice.IntentAPI, portal *Portal, unmute bool) {
if len(portal.MXID) == 0 || !user.bridge.Config.Bridge.MuteChannelsOnCreate {
return
}
var err error
if unmute {
user.log.Debugfln("Unmuting portal %s", portal.MXID)
err = intent.DeletePushRule("global", pushrules.RoomRule, string(portal.MXID))
} else {
user.log.Debugfln("Muting portal %s", portal.MXID)
err = intent.PutPushRule("global", pushrules.RoomRule, string(portal.MXID), &mautrix.ReqPutPushRule{
Actions: []pushrules.PushActionType{pushrules.ActionDontNotify},
})
}
if err != nil && !errors.Is(err, mautrix.MNotFound) {
user.log.Warnfln("Failed to update push rule for %s through double puppet: %v", portal.MXID, err)
}
}
func (user *User) syncChatDoublePuppetDetails(portal *Portal, justCreated bool) {
doublePuppet := portal.bridge.GetPuppetByCustomMXID(user.MXID)
if doublePuppet == nil {
doublePuppetIntent := portal.bridge.GetPuppetByCustomMXID(user.MXID).CustomIntent()
if doublePuppetIntent == nil || portal.MXID == "" {
return
}
if doublePuppet == nil || doublePuppet.CustomIntent() == nil || portal.MXID == "" {
return
// TODO sync mute status properly
if portal.GuildID != "" && user.bridge.Config.Bridge.MuteChannelsOnCreate {
go user.mutePortal(doublePuppetIntent, portal, false)
}
// TODO sync mute status
}
func (user *User) Login(token string) error {