Compare commits

...

10 Commits

6 changed files with 42 additions and 25 deletions

View File

@ -94,27 +94,28 @@ type BridgeConfig struct {
DoublePuppetConfig bridgeconfig.DoublePuppetConfig `yaml:",inline"`
PrivateChatPortalMeta string `yaml:"private_chat_portal_meta"`
ParallelMemberSync bool `yaml:"parallel_member_sync"`
BridgeNotices bool `yaml:"bridge_notices"`
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
MuteBridging bool `yaml:"mute_bridging"`
ArchiveTag string `yaml:"archive_tag"`
PinnedTag string `yaml:"pinned_tag"`
TagOnlyOnCreate bool `yaml:"tag_only_on_create"`
MarkReadOnlyOnCreate bool `yaml:"mark_read_only_on_create"`
EnableStatusBroadcast bool `yaml:"enable_status_broadcast"`
MuteStatusBroadcast bool `yaml:"mute_status_broadcast"`
StatusBroadcastTag string `yaml:"status_broadcast_tag"`
WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"`
AllowUserInvite bool `yaml:"allow_user_invite"`
FederateRooms bool `yaml:"federate_rooms"`
URLPreviews bool `yaml:"url_previews"`
CaptionInMessage bool `yaml:"caption_in_message"`
BeeperGalleries bool `yaml:"beeper_galleries"`
ExtEvPolls bool `yaml:"extev_polls"`
CrossRoomReplies bool `yaml:"cross_room_replies"`
DisableReplyFallbacks bool `yaml:"disable_reply_fallbacks"`
PrivateChatPortalMeta string `yaml:"private_chat_portal_meta"`
ParallelMemberSync bool `yaml:"parallel_member_sync"`
BridgeNotices bool `yaml:"bridge_notices"`
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
MuteBridging bool `yaml:"mute_bridging"`
ArchiveTag string `yaml:"archive_tag"`
PinnedTag string `yaml:"pinned_tag"`
TagOnlyOnCreate bool `yaml:"tag_only_on_create"`
MarkReadOnlyOnCreate bool `yaml:"mark_read_only_on_create"`
EnableStatusBroadcast bool `yaml:"enable_status_broadcast"`
MuteStatusBroadcast bool `yaml:"mute_status_broadcast"`
StatusBroadcastTag string `yaml:"status_broadcast_tag"`
WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"`
AllowUserInvite bool `yaml:"allow_user_invite"`
FederateRooms bool `yaml:"federate_rooms"`
URLPreviews bool `yaml:"url_previews"`
CaptionInMessage bool `yaml:"caption_in_message"`
BeeperGalleries bool `yaml:"beeper_galleries"`
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"`

View File

@ -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")

View File

@ -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:

2
go.mod
View File

@ -14,7 +14,7 @@ require (
github.com/tidwall/gjson v1.17.1
go.mau.fi/util v0.4.1
go.mau.fi/webp v0.1.0
go.mau.fi/whatsmeow v0.0.0-20240316104858-18372a0653fa
go.mau.fi/whatsmeow v0.0.0-20240326141755-051606b388f6
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f
golang.org/x/image v0.15.0
golang.org/x/net v0.22.0

4
go.sum
View File

@ -73,8 +73,8 @@ go.mau.fi/util v0.4.1 h1:3EC9KxIXo5+h869zDGf5OOZklRd/FjeVnimTwtm3owg=
go.mau.fi/util v0.4.1/go.mod h1:GjkTEBsehYZbSh2LlE6cWEn+6ZIZTGrTMM/5DMNlmFY=
go.mau.fi/webp v0.1.0 h1:BHObH/DcFntT9KYun5pDr0Ot4eUZO8k2C7eP7vF4ueA=
go.mau.fi/webp v0.1.0/go.mod h1:e42Z+VMFrUMS9cpEwGRIor+lQWO8oUAyPyMtcL+NMt8=
go.mau.fi/whatsmeow v0.0.0-20240316104858-18372a0653fa h1:ifQivrTMLAAkBkIqdE/D56uAZyc7ziRdhUU59VfNPFg=
go.mau.fi/whatsmeow v0.0.0-20240316104858-18372a0653fa/go.mod h1:kNI5foyzqd77d5HaWc1Jico6/rxtZ/UE8nr80hIsbIk=
go.mau.fi/whatsmeow v0.0.0-20240326141755-051606b388f6 h1:CbU9Vq9Bvh03sk+xZO4FOaMTasuPiJbwyqWZsBa+gko=
go.mau.fi/whatsmeow v0.0.0-20240326141755-051606b388f6/go.mod h1:kNI5foyzqd77d5HaWc1Jico6/rxtZ/UE8nr80hIsbIk=
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
go.mau.fi/zeroconfig v0.1.2/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=

View File

@ -1224,7 +1224,7 @@ func (portal *Portal) getMessageIntent(ctx context.Context, user *User, info *ty
return nil
}
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")
return nil
}
@ -2188,6 +2188,10 @@ func (portal *Portal) CreateMatrixRoom(ctx context.Context, user *User, groupInf
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() {
initialState = append(initialState, &event.Event{
Type: event.StateRoomAvatar,
@ -2311,6 +2315,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")
}
}
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}})
} else if portal.IsParent {