From 172ce83318a4d4d14249891ef9d4c036c6122d8a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 19 Apr 2023 17:26:21 +0300 Subject: [PATCH] Add option to disable reply fallbacks --- config/bridge.go | 1 + config/upgrade.go | 1 + example-config.yaml | 3 +++ portal.go | 5 ++++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config/bridge.go b/config/bridge.go index 3046d92..6f3d75f 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -118,6 +118,7 @@ type BridgeConfig struct { CaptionInMessage bool `yaml:"caption_in_message"` ExtEvPolls bool `yaml:"extev_polls"` CrossRoomReplies bool `yaml:"cross_room_replies"` + DisableReplyFallbacks bool `yaml:"disable_reply_fallbacks"` MessageHandlingTimeout struct { ErrorAfterStr string `yaml:"error_after"` diff --git a/config/upgrade.go b/config/upgrade.go index 4a137e6..32ba458 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -115,6 +115,7 @@ func DoUpgrade(helper *up.Helper) { helper.Copy(up.Bool, "bridge", "extev_polls") } helper.Copy(up.Bool, "bridge", "cross_room_replies") + helper.Copy(up.Bool, "bridge", "disable_reply_fallbacks") 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 93f1eb8..a636e58 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -313,6 +313,9 @@ bridge: extev_polls: false # Should cross-chat replies from WhatsApp be bridged? Most servers and clients don't support this. cross_room_replies: false + # 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 # 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 4d3acf1..277a757 100644 --- a/portal.go +++ b/portal.go @@ -1912,10 +1912,13 @@ func (portal *Portal) SetReply(content *event.MessageEventContent, replyTo *Repl } return false } + content.RelatesTo = (&event.RelatesTo{}).SetReplyTo(message.MXID) + if portal.bridge.Config.Bridge.DisableReplyFallbacks { + return true + } evt, err := targetPortal.MainIntent().GetEvent(targetPortal.MXID, message.MXID) if err != nil { portal.log.Warnln("Failed to get reply target:", err) - content.RelatesTo = (&event.RelatesTo{}).SetReplyTo(message.MXID) return true } _ = evt.Content.ParseRaw(evt.Type)