mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-17 22:42:01 -08:00
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:
parent
ac2f7da59d
commit
e168a89632
@ -362,20 +362,14 @@ func (b *Bxmpp) replaceAction(text string) (string, bool) {
|
|||||||
|
|
||||||
// handleUploadFile handles native upload of files
|
// handleUploadFile handles native upload of files
|
||||||
func (b *Bxmpp) handleUploadFile(msg *config.Message) error {
|
func (b *Bxmpp) handleUploadFile(msg *config.Message) error {
|
||||||
var urlDesc string
|
|
||||||
|
|
||||||
for _, file := range msg.Extra["file"] {
|
for _, file := range msg.Extra["file"] {
|
||||||
fileInfo := file.(config.FileInfo)
|
fileInfo := file.(config.FileInfo)
|
||||||
if fileInfo.Comment != "" {
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is sent even if Text is empty,
|
||||||
|
// so that you can tell who sent the message
|
||||||
if _, err := b.xc.Send(xmpp.Chat{
|
if _, err := b.xc.Send(xmpp.Chat{
|
||||||
Type: "groupchat",
|
Type: "groupchat",
|
||||||
Remote: msg.Channel + "@" + b.GetString("Muc"),
|
Remote: msg.Channel + "@" + b.GetString("Muc"),
|
||||||
@ -385,13 +379,14 @@ func (b *Bxmpp) handleUploadFile(msg *config.Message) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fileInfo.URL != "" {
|
if fileInfo.URL != "" {
|
||||||
if _, err := b.xc.SendOOB(xmpp.Chat{
|
if _, err := b.xc.Send(xmpp.Chat{
|
||||||
Type: "groupchat",
|
Type: "groupchat",
|
||||||
Remote: msg.Channel + "@" + b.GetString("Muc"),
|
Remote: msg.Channel + "@" + b.GetString("Muc"),
|
||||||
|
Text: fileInfo.URL,
|
||||||
Ooburl: fileInfo.URL,
|
Ooburl: fileInfo.URL,
|
||||||
Oobdesc: urlDesc,
|
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
b.Log.WithError(err).Warn("Failed to send share URL.")
|
b.Log.WithError(err).Warn("Failed to send share URL.")
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user