From 4b0a87c3f2cdd09e47517edb735668692e61e44d Mon Sep 17 00:00:00 2001 From: Board Date: Mon, 3 Nov 2025 23:17:30 -0800 Subject: [PATCH] Remove fallback quoted msgs in XMPP replies --- bridge/xmpp/helpers.go | 22 ++++++++++++++++++++++ bridge/xmpp/xmpp.go | 1 + 2 files changed, 23 insertions(+) diff --git a/bridge/xmpp/helpers.go b/bridge/xmpp/helpers.go index eb6a5366..b2530f7e 100644 --- a/bridge/xmpp/helpers.go +++ b/bridge/xmpp/helpers.go @@ -1,7 +1,9 @@ package bxmpp import ( + "bufio" "regexp" + "strings" "github.com/42wim/matterbridge/bridge/config" ) @@ -28,3 +30,23 @@ func (b *Bxmpp) cacheAvatar(msg *config.Message) string { } return "" } + +func trimLeadingQuotedLines(s string) string { + scanner := bufio.NewScanner(strings.NewReader(s)) + var builder strings.Builder + skipping := true + + for scanner.Scan() { + line := scanner.Text() + if skipping { + if strings.HasPrefix(line, "> ") { + // still skipping + continue + } + skipping = false + } + builder.WriteString(line + "\n") + } + + return strings.TrimRight(builder.String(), "\n") +} diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 42bc15f0..82c3d700 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -347,6 +347,7 @@ func (b *Bxmpp) handleXMPP() error { var parentID string if res, ok := b.OriginIDs.Get(v.ReplyID); ok { parentID, _ = res.(string) + v.Text = trimLeadingQuotedLines(v.Text) } rmsg := config.Message{