forked from MirrorHub/mautrix-whatsapp
feat: add config option for self puppets
This commit is contained in:
parent
074745a3b5
commit
e418e7df7c
4 changed files with 38 additions and 26 deletions
|
@ -115,6 +115,7 @@ type BridgeConfig struct {
|
|||
ExtEvPolls bool `yaml:"extev_polls"`
|
||||
CrossRoomReplies bool `yaml:"cross_room_replies"`
|
||||
DisableReplyFallbacks bool `yaml:"disable_reply_fallbacks"`
|
||||
PrivateChatSelfPuppets bool `yaml:"private_chat_self_puppets"`
|
||||
|
||||
MessageHandlingTimeout struct {
|
||||
ErrorAfterStr string `yaml:"error_after"`
|
||||
|
|
|
@ -115,6 +115,7 @@ func DoUpgrade(helper *up.Helper) {
|
|||
}
|
||||
helper.Copy(up.Bool, "bridge", "cross_room_replies")
|
||||
helper.Copy(up.Bool, "bridge", "disable_reply_fallbacks")
|
||||
helper.Copy(up.Bool, "bridge", "private_chat_self_puppets")
|
||||
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "error_after")
|
||||
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "deadline")
|
||||
|
||||
|
|
|
@ -313,6 +313,10 @@ bridge:
|
|||
# Disable generating reply fallbacks? Some extremely bad clients still rely on them,
|
||||
# but they're being phased out and will be completely removed in the future.
|
||||
disable_reply_fallbacks: false
|
||||
# Invite the puppet which represents the bridge user into private chats?
|
||||
# This allows proper backfilling in private chats without double puppeting enabled,
|
||||
# but adds an additional puppet user to each private chat.
|
||||
private_chat_self_puppets: false
|
||||
# Maximum time for handling Matrix events. Duration strings formatted for https://pkg.go.dev/time#ParseDuration
|
||||
# Null means there's no enforced timeout.
|
||||
message_handling_timeout:
|
||||
|
|
|
@ -1097,6 +1097,10 @@ func (portal *Portal) getMessageIntent(user *User, info *types.MessageInfo, msgT
|
|||
return nil
|
||||
}
|
||||
intent := puppet.IntentFor(portal)
|
||||
if !portal.bridge.Config.Bridge.PrivateChatSelfPuppets && !intent.IsCustomPuppet && portal.IsPrivateChat() && info.Sender.User == portal.Key.Receiver.User && portal.Key.Receiver != portal.Key.JID {
|
||||
portal.log.Debugfln("Not handling %s (%s): user doesn't have double puppeting enabled", info.ID, msgType)
|
||||
return nil
|
||||
}
|
||||
return intent
|
||||
}
|
||||
|
||||
|
@ -1983,7 +1987,7 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, n
|
|||
invite = append(invite, portal.bridge.Bot.UserID)
|
||||
}
|
||||
}
|
||||
if portal.IsPrivateChat() {
|
||||
if portal.IsPrivateChat() && portal.bridge.Config.Bridge.PrivateChatSelfPuppets {
|
||||
rec := portal.bridge.GetPuppetByJID(portal.Key.Receiver)
|
||||
invite = append(invite, rec.MXID)
|
||||
}
|
||||
|
@ -2103,11 +2107,13 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, n
|
|||
portal.log.Errorln("Failed to join created portal with bridge bot for e2be:", err)
|
||||
}
|
||||
}
|
||||
if portal.bridge.Config.Bridge.PrivateChatSelfPuppets {
|
||||
rec := portal.bridge.GetPuppetByJID(portal.Key.Receiver)
|
||||
err = rec.DefaultIntent().EnsureJoined(portal.MXID)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Failed to join created portal with puppet:", err)
|
||||
}
|
||||
}
|
||||
|
||||
user.UpdateDirectChats(map[id.UserID][]id.RoomID{puppet.MXID: {portal.MXID}})
|
||||
} else if portal.IsParent {
|
||||
|
|
Loading…
Reference in a new issue