Compare commits

...

9 commits

4 changed files with 39 additions and 22 deletions

View file

@ -116,6 +116,7 @@ type BridgeConfig struct {
ExtEvPolls bool `yaml:"extev_polls"` ExtEvPolls bool `yaml:"extev_polls"`
CrossRoomReplies bool `yaml:"cross_room_replies"` CrossRoomReplies bool `yaml:"cross_room_replies"`
DisableReplyFallbacks bool `yaml:"disable_reply_fallbacks"` DisableReplyFallbacks bool `yaml:"disable_reply_fallbacks"`
PrivateChatSelfPuppets bool `yaml:"private_chat_self_puppets"`
MessageHandlingTimeout struct { MessageHandlingTimeout struct {
ErrorAfterStr string `yaml:"error_after"` ErrorAfterStr string `yaml:"error_after"`

View file

@ -116,6 +116,7 @@ func DoUpgrade(helper *up.Helper) {
} }
helper.Copy(up.Bool, "bridge", "cross_room_replies") helper.Copy(up.Bool, "bridge", "cross_room_replies")
helper.Copy(up.Bool, "bridge", "disable_reply_fallbacks") 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", "error_after")
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "deadline") helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "deadline")

View file

@ -315,6 +315,10 @@ bridge:
# Disable generating reply fallbacks? Some extremely bad clients still rely on them, # 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. # but they're being phased out and will be completely removed in the future.
disable_reply_fallbacks: false 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 # Maximum time for handling Matrix events. Duration strings formatted for https://pkg.go.dev/time#ParseDuration
# Null means there's no enforced timeout. # Null means there's no enforced timeout.
message_handling_timeout: message_handling_timeout:

View file

@ -1216,7 +1216,7 @@ func (portal *Portal) getMessageIntent(ctx context.Context, user *User, info *ty
return nil return nil
} }
intent := puppet.IntentFor(portal) intent := puppet.IntentFor(portal)
if !intent.IsCustomPuppet && portal.IsPrivateChat() && info.Sender.User == portal.Key.Receiver.User && portal.Key.Receiver != portal.Key.JID { if !portal.bridge.Config.Bridge.PrivateChatSelfPuppets && !intent.IsCustomPuppet && portal.IsPrivateChat() && info.Sender.User == portal.Key.Receiver.User && portal.Key.Receiver != portal.Key.JID {
zerolog.Ctx(ctx).Debug().Msg("Not handling message: user doesn't have double puppeting enabled") zerolog.Ctx(ctx).Debug().Msg("Not handling message: user doesn't have double puppeting enabled")
return nil return nil
} }
@ -2180,6 +2180,10 @@ func (portal *Portal) CreateMatrixRoom(ctx context.Context, user *User, groupInf
invite = append(invite, portal.bridge.Bot.UserID) invite = append(invite, portal.bridge.Bot.UserID)
} }
} }
if portal.IsPrivateChat() && portal.bridge.Config.Bridge.PrivateChatSelfPuppets {
rec := portal.bridge.GetPuppetByJID(portal.Key.Receiver)
invite = append(invite, rec.MXID)
}
if !portal.AvatarURL.IsEmpty() && portal.shouldSetDMRoomMetadata() { if !portal.AvatarURL.IsEmpty() && portal.shouldSetDMRoomMetadata() {
initialState = append(initialState, &event.Event{ initialState = append(initialState, &event.Event{
Type: event.StateRoomAvatar, Type: event.StateRoomAvatar,
@ -2303,6 +2307,13 @@ func (portal *Portal) CreateMatrixRoom(ctx context.Context, user *User, groupInf
log.Err(err).Msg("Failed to ensure bridge bot is joined to created portal") log.Err(err).Msg("Failed to ensure bridge bot is joined to created portal")
} }
} }
if portal.bridge.Config.Bridge.PrivateChatSelfPuppets {
rec := portal.bridge.GetPuppetByJID(portal.Key.Receiver)
err = rec.DefaultIntent().EnsureJoined(ctx, portal.MXID)
if err != nil {
log.Err(err).Msg("Failed to join created portal with puppet")
}
}
user.UpdateDirectChats(ctx, map[id.UserID][]id.RoomID{puppet.MXID: {portal.MXID}}) user.UpdateDirectChats(ctx, map[id.UserID][]id.RoomID{puppet.MXID: {portal.MXID}})
} else if portal.IsParent { } else if portal.IsParent {