Resolve issue #1381.

Make function SendOOB in vendor/github.com/matterbridge/go-xmpp/xmpp.go to send meesage 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.
Moreover, send the media attachement first, then the message.
This commit is contained in:
allilengyi
2021-03-19 23:41:18 +01:00
parent 3a8857c8c9
commit 634b98b273
2 changed files with 12 additions and 16 deletions

View File

@@ -352,24 +352,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 +367,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
}