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
This commit is contained in:
ubq323 2024-08-16 09:02:07 +01:00
parent ac2f7da59d
commit e168a89632

View File

@ -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
}
}
}