Send attached files to XMPP in different message with OOB data and without body (#421)

Conversations can't show inline pictures if there's anything besides URL in the message body.
Workaround this issue by sending one usual message and one message with OOB data and without message body.
The second message should not be shown in the clients without OOB support, so the user won't see the empty message.
This commit is contained in:
ValdikSS 2018-05-10 00:04:10 +03:00 committed by Wim
parent 85b2d5a124
commit be04d1a862

View File

@ -180,6 +180,7 @@ 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) (string, error) { func (b *Bxmpp) handleUploadFile(msg *config.Message) (string, error) {
var urldesc = ""
for _, f := range msg.Extra["file"] { for _, f := range msg.Extra["file"] {
fi := f.(config.FileInfo) fi := f.(config.FileInfo)
if fi.Comment != "" { if fi.Comment != "" {
@ -189,12 +190,16 @@ func (b *Bxmpp) handleUploadFile(msg *config.Message) (string, error) {
msg.Text = fi.URL msg.Text = fi.URL
if fi.Comment != "" { if fi.Comment != "" {
msg.Text = fi.Comment + ": " + fi.URL msg.Text = fi.Comment + ": " + fi.URL
urldesc = fi.Comment
} }
} }
_, err := b.xc.Send(xmpp.Chat{Type: "groupchat", Remote: msg.Channel + "@" + b.GetString("Muc"), Text: msg.Username + msg.Text}) _, err := b.xc.Send(xmpp.Chat{Type: "groupchat", Remote: msg.Channel + "@" + b.GetString("Muc"), Text: msg.Username + msg.Text})
if err != nil { if err != nil {
return "", err return "", err
} }
if fi.URL != "" {
b.xc.SendOOB(xmpp.Chat{Type: "groupchat", Remote: msg.Channel + "@" + b.GetString("Muc"), Ooburl: fi.URL, Oobdesc: urldesc})
}
} }
return "", nil return "", nil
} }