Add hacky option to mute all guild channels on create
This commit is contained in:
@@ -42,6 +42,7 @@ type BridgeConfig struct {
|
|||||||
MessageErrorNotices bool `yaml:"message_error_notices"`
|
MessageErrorNotices bool `yaml:"message_error_notices"`
|
||||||
RestrictedRooms bool `yaml:"restricted_rooms"`
|
RestrictedRooms bool `yaml:"restricted_rooms"`
|
||||||
AutojoinThreadOnOpen bool `yaml:"autojoin_thread_on_open"`
|
AutojoinThreadOnOpen bool `yaml:"autojoin_thread_on_open"`
|
||||||
|
MuteChannelsOnCreate bool `yaml:"mute_channels_on_create"`
|
||||||
SyncDirectChatList bool `yaml:"sync_direct_chat_list"`
|
SyncDirectChatList bool `yaml:"sync_direct_chat_list"`
|
||||||
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
|
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
|
||||||
DeletePortalOnChannelDelete bool `yaml:"delete_portal_on_channel_delete"`
|
DeletePortalOnChannelDelete bool `yaml:"delete_portal_on_channel_delete"`
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ func DoUpgrade(helper *up.Helper) {
|
|||||||
helper.Copy(up.Bool, "bridge", "message_error_notices")
|
helper.Copy(up.Bool, "bridge", "message_error_notices")
|
||||||
helper.Copy(up.Bool, "bridge", "restricted_rooms")
|
helper.Copy(up.Bool, "bridge", "restricted_rooms")
|
||||||
helper.Copy(up.Bool, "bridge", "autojoin_thread_on_open")
|
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", "sync_direct_chat_list")
|
||||||
helper.Copy(up.Bool, "bridge", "resend_bridge_info")
|
helper.Copy(up.Bool, "bridge", "resend_bridge_info")
|
||||||
helper.Copy(up.Bool, "bridge", "delete_portal_on_channel_delete")
|
helper.Copy(up.Bool, "bridge", "delete_portal_on_channel_delete")
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ bridge:
|
|||||||
# Should the bridge automatically join the user to threads on Discord when the thread is opened on Matrix?
|
# 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).
|
# This only works with clients that support thread read receipts (MSC3771 added in Matrix v1.4).
|
||||||
autojoin_thread_on_open: true
|
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.
|
# 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)
|
# Note that updating the m.direct event is not atomic (except with mautrix-asmux)
|
||||||
# and is therefore prone to race conditions.
|
# and is therefore prone to race conditions.
|
||||||
|
|||||||
@@ -178,6 +178,9 @@ func (puppet *Puppet) IntentFor(portal *Portal) *appservice.IntentAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) CustomIntent() *appservice.IntentAPI {
|
func (puppet *Puppet) CustomIntent() *appservice.IntentAPI {
|
||||||
|
if puppet == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return puppet.customIntent
|
return puppet.customIntent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
user.go
31
user.go
@@ -22,6 +22,7 @@ import (
|
|||||||
"maunium.net/go/mautrix/bridge/status"
|
"maunium.net/go/mautrix/bridge/status"
|
||||||
"maunium.net/go/mautrix/event"
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
"maunium.net/go/mautrix/pushrules"
|
||||||
|
|
||||||
"go.mau.fi/mautrix-discord/database"
|
"go.mau.fi/mautrix-discord/database"
|
||||||
)
|
)
|
||||||
@@ -392,17 +393,35 @@ func (user *User) ViewingChannel(portal *Portal) bool {
|
|||||||
return false
|
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) {
|
func (user *User) syncChatDoublePuppetDetails(portal *Portal, justCreated bool) {
|
||||||
doublePuppet := portal.bridge.GetPuppetByCustomMXID(user.MXID)
|
doublePuppetIntent := portal.bridge.GetPuppetByCustomMXID(user.MXID).CustomIntent()
|
||||||
if doublePuppet == nil {
|
if doublePuppetIntent == nil || portal.MXID == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if doublePuppet == nil || doublePuppet.CustomIntent() == nil || portal.MXID == "" {
|
// TODO sync mute status properly
|
||||||
return
|
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 {
|
func (user *User) Login(token string) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user