From 634b98b273eb4a7d3f3ceeb3fc979b2f4e7837d5 Mon Sep 17 00:00:00 2001 From: allilengyi Date: Fri, 19 Mar 2021 23:41:18 +0100 Subject: [PATCH] Resolve issue #1381. Make function SendOOB in vendor/github.com/matterbridge/go-xmpp/xmpp.go to send meesage with actual body according to https://github.com/42wim/matterbridge/issues/1381#issuecomment-774032477. Remove the appendage ":" + fileInfo.URL in bridge/xmpp/xmpp.go. This will not modify the message so that the link to the file is not sent in the text message. Instead the media file is available as inline display in modern XMPP clients. Moreover, send the media attachement first, then the message. --- bridge/xmpp/xmpp.go | 21 +++++++------------ .../github.com/matterbridge/go-xmpp/xmpp.go | 7 ++++--- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 89a48742..0a9db609 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -352,24 +352,12 @@ func (b *Bxmpp) handleUploadFile(msg *config.Message) error { for _, file := range msg.Extra["file"] { fileInfo := file.(config.FileInfo) if fileInfo.Comment != "" { - msg.Text += fileInfo.Comment + ": " + msg.Text += fileInfo.Comment } if fileInfo.URL != "" { - msg.Text = fileInfo.URL if fileInfo.Comment != "" { - msg.Text = fileInfo.Comment + ": " + fileInfo.URL urlDesc = fileInfo.Comment } - } - if _, err := b.xc.Send(xmpp.Chat{ - Type: "groupchat", - Remote: msg.Channel + "@" + b.GetString("Muc"), - Text: msg.Username + msg.Text, - }); err != nil { - return err - } - - if fileInfo.URL != "" { if _, err := b.xc.SendOOB(xmpp.Chat{ Type: "groupchat", Remote: msg.Channel + "@" + b.GetString("Muc"), @@ -379,6 +367,13 @@ func (b *Bxmpp) handleUploadFile(msg *config.Message) error { b.Log.WithError(err).Warn("Failed to send share URL.") } } + if _, err := b.xc.Send(xmpp.Chat{ + Type: "groupchat", + Remote: msg.Channel + "@" + b.GetString("Muc"), + Text: msg.Username + msg.Text, + }); err != nil { + return err + } } return nil } diff --git a/vendor/github.com/matterbridge/go-xmpp/xmpp.go b/vendor/github.com/matterbridge/go-xmpp/xmpp.go index 56b08f5b..ae2a08e5 100644 --- a/vendor/github.com/matterbridge/go-xmpp/xmpp.go +++ b/vendor/github.com/matterbridge/go-xmpp/xmpp.go @@ -875,7 +875,7 @@ func (c *Client) Send(chat Chat) (n int, err error) { return fmt.Fprintf(c.conn, stanza, xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text)) } -// SendOOB sends OOB data wrapped inside an XMPP message stanza, without actual body. +// SendOOB sends OOB data wrapped inside an XMPP message stanza, with actual body to trigger inline display for modern XMPP clients func (c *Client) SendOOB(chat Chat) (n int, err error) { var thdtext, oobtext string if chat.Thread != `` { @@ -888,8 +888,9 @@ func (c *Client) SendOOB(chat Chat) (n int, err error) { } oobtext += `` } - return fmt.Fprintf(c.conn, ""+oobtext+thdtext+"", - xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce()) + stanza := " "+xmlEscape(chat.Ooburl)+"" + oobtext + thdtext + "" + + return fmt.Fprintf(c.conn, stanza, xmlEscape(chat.Remote), xmlEscape(chat.Type),cnonce()) } // SendOrg sends the original text without being wrapped in an XMPP message stanza.