From e168a89632bff7b75fa12085367e28ea2e0a04c9 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 16 Aug 2024 09:02:07 +0100 Subject: [PATCH] xmpp: set body text to attachment URL in XEP-0066 OOB messages many clients will only display files inline if the message body itself exactly matches the attachment URL. see https://docs.modernxmpp.org/client/protocol/#communicating-the-url --- bridge/xmpp/xmpp.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index cf58a2fc..54649324 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -362,20 +362,14 @@ func (b *Bxmpp) replaceAction(text string) (string, bool) { // handleUploadFile handles native upload of files func (b *Bxmpp) handleUploadFile(msg *config.Message) error { - var urlDesc string - for _, file := range msg.Extra["file"] { fileInfo := file.(config.FileInfo) if 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 - } + msg.Text += fileInfo.Comment } + + // this is sent even if Text is empty, + // so that you can tell who sent the message if _, err := b.xc.Send(xmpp.Chat{ Type: "groupchat", Remote: msg.Channel + "@" + b.GetString("Muc"), @@ -385,13 +379,14 @@ func (b *Bxmpp) handleUploadFile(msg *config.Message) error { } if fileInfo.URL != "" { - if _, err := b.xc.SendOOB(xmpp.Chat{ + if _, err := b.xc.Send(xmpp.Chat{ Type: "groupchat", Remote: msg.Channel + "@" + b.GetString("Muc"), + Text: fileInfo.URL, Ooburl: fileInfo.URL, - Oobdesc: urlDesc, }); err != nil { b.Log.WithError(err).Warn("Failed to send share URL.") + return err } } }