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:
@@ -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
|
||||
}
|
||||
|
||||
7
vendor/github.com/matterbridge/go-xmpp/xmpp.go
generated
vendored
7
vendor/github.com/matterbridge/go-xmpp/xmpp.go
generated
vendored
@@ -875,7 +875,7 @@ func (c *Client) Send(chat Chat) (n int, err error) {
|
||||
return fmt.Fprintf(c.conn, stanza, xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||
}
|
||||
|
||||
// SendOOB sends OOB data wrapped inside an XMPP message stanza, without actual body.
|
||||
// SendOOB sends OOB data wrapped inside an XMPP message stanza, with actual body to trigger inline display for modern XMPP clients
|
||||
func (c *Client) SendOOB(chat Chat) (n int, err error) {
|
||||
var thdtext, oobtext string
|
||||
if chat.Thread != `` {
|
||||
@@ -888,8 +888,9 @@ func (c *Client) SendOOB(chat Chat) (n int, err error) {
|
||||
}
|
||||
oobtext += `</x>`
|
||||
}
|
||||
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' id='%s' xml:lang='en'>"+oobtext+thdtext+"</message>",
|
||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce())
|
||||
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'> <body>"+xmlEscape(chat.Ooburl)+"</body>" + oobtext + thdtext + "</message>"
|
||||
|
||||
return fmt.Fprintf(c.conn, stanza, xmlEscape(chat.Remote), xmlEscape(chat.Type),cnonce())
|
||||
}
|
||||
|
||||
// SendOrg sends the original text without being wrapped in an XMPP message stanza.
|
||||
|
||||
Reference in New Issue
Block a user