From 5c80732064845183b066e20f52d4ebd443d90516 Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Sun, 11 Jun 2023 16:42:26 +0200 Subject: [PATCH 1/6] fix: invite own puppet to private portals --- portal.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/portal.go b/portal.go index 1e9217b..1b750b2 100644 --- a/portal.go +++ b/portal.go @@ -1637,6 +1637,10 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, i invite = append(invite, portal.bridge.Bot.UserID) } } + if portal.IsPrivateChat() { + 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, From fae313fa329b3d9677912f9f7a407c560524ce2b Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Sun, 11 Jun 2023 17:17:05 +0200 Subject: [PATCH 2/6] fix: ensure joined --- portal.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/portal.go b/portal.go index 1b750b2..9ce1d92 100644 --- a/portal.go +++ b/portal.go @@ -1747,6 +1747,11 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, i portal.log.Errorln("Failed to join created portal with bridge bot for e2be:", err) } } + rec := portal.bridge.GetPuppetByJID(portal.Key.Receiver) + err = rec.CustomIntent().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 { From 7c692aebaef0e106fd084a0fb2b4e2d1707d748c Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Sun, 11 Jun 2023 17:57:15 +0200 Subject: [PATCH 3/6] fix: use right intent --- portal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portal.go b/portal.go index 9ce1d92..8a142ce 100644 --- a/portal.go +++ b/portal.go @@ -1748,7 +1748,7 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, i } } rec := portal.bridge.GetPuppetByJID(portal.Key.Receiver) - err = rec.CustomIntent().EnsureJoined(portal.MXID) + err = rec.DefaultIntent().EnsureJoined(portal.MXID) if err != nil { portal.log.Errorln("Failed to join created portal with puppet:", err) } From 074745a3b5a40dcd39739e7474ba015655452d50 Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Thu, 29 Feb 2024 21:13:40 +0100 Subject: [PATCH 4/6] feat: backfill direct messages without double-puppeting --- portal.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/portal.go b/portal.go index d1373b8..8754c0a 100644 --- a/portal.go +++ b/portal.go @@ -1097,10 +1097,6 @@ func (portal *Portal) getMessageIntent(user *User, info *types.MessageInfo, msgT return nil } intent := puppet.IntentFor(portal) - if !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 } From e418e7df7c6e3c7864a35c729a9ced4aeb2ce9eb Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Fri, 1 Mar 2024 09:45:43 +0100 Subject: [PATCH 5/6] feat: add config option for self puppets --- config/bridge.go | 43 ++++++++++++++++++++++--------------------- config/upgrade.go | 1 + example-config.yaml | 4 ++++ portal.go | 16 +++++++++++----- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/config/bridge.go b/config/bridge.go index 538908f..1ebdccb 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -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"` diff --git a/config/upgrade.go b/config/upgrade.go index b1999c8..7449556 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -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") diff --git a/example-config.yaml b/example-config.yaml index 058f3e1..ce4931b 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -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: diff --git a/portal.go b/portal.go index 8754c0a..128288f 100644 --- a/portal.go +++ b/portal.go @@ -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,10 +2107,12 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, n portal.log.Errorln("Failed to join created portal with bridge bot for e2be:", err) } } - 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) + 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}}) From 196e5bc1066f20698054b1b8b042c34a572f9ee5 Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Tue, 12 Mar 2024 12:37:58 +0100 Subject: [PATCH 6/6] fix: call EnsureJoined with ctx --- portal.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/portal.go b/portal.go index 4bc45d8..5b4eaa0 100644 --- a/portal.go +++ b/portal.go @@ -2313,9 +2313,9 @@ func (portal *Portal) CreateMatrixRoom(ctx context.Context, user *User, groupInf } if portal.bridge.Config.Bridge.PrivateChatSelfPuppets { rec := portal.bridge.GetPuppetByJID(portal.Key.Receiver) - err = rec.DefaultIntent().EnsureJoined(portal.MXID) + err = rec.DefaultIntent().EnsureJoined(ctx, portal.MXID) if err != nil { - portal.log.Errorln("Failed to join created portal with puppet:", err) + log.Err(err).Msg("Failed to join created portal with puppet") } }