From 2312058035076675b1b395028e129935133ce7e6 Mon Sep 17 00:00:00 2001 From: allilengyi Date: Wed, 24 Feb 2021 20:24:29 +0100 Subject: [PATCH] Make function SendOOB in vendor/github.com/matterbridge/go-xmpp/xmpp.go to send *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. --- bridge/xmpp/xmpp.go | 37 +++++++------------ .../github.com/matterbridge/go-xmpp/xmpp.go | 8 ++-- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 89a48742..0ee0cf76 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -6,14 +6,13 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "strings" "sync" "time" - "github.com/42wim/matterbridge/bridge" - "github.com/42wim/matterbridge/bridge/config" - "github.com/42wim/matterbridge/bridge/helper" + "github.com/allilengyi/matterbridge/bridge" + "github.com/allilengyi/matterbridge/bridge/config" + "github.com/allilengyi/matterbridge/bridge/helper" "github.com/jpillora/backoff" "github.com/matterbridge/go-xmpp" "github.com/rs/xid" @@ -158,14 +157,9 @@ func (b *Bxmpp) postSlackCompatibleWebhook(msg config.Message) error { return err } - resp, err := http.Post(b.GetString("WebhookURL")+"/"+url.QueryEscape(msg.Channel), "application/json", bytes.NewReader(webhookBody)) - if err != nil { - b.Log.Errorf("Failed to POST webhook: %s", err) - return err - } - + resp, err := http.Post(b.GetString("WebhookURL")+"/"+msg.Channel, "application/json", bytes.NewReader(webhookBody)) resp.Body.Close() - return nil + return err } func (b *Bxmpp) createXMPP() error { @@ -352,24 +346,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 +361,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..537a6259 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 download for modern XMPP clients func (c *Client) SendOOB(chat Chat) (n int, err error) { var thdtext, oobtext string if chat.Thread != `` { @@ -888,8 +888,10 @@ 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.