mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2026-05-23 20:33:46 -07:00
Implement OOB in Send() and add SendOOB() function for messages without body (#117)
Co-authored-by: Qais Patankar <qaisjp@gmail.com> Co-authored-by: ValdikSS <iam@valdikss.org.ru>
This commit is contained in:
@@ -597,6 +597,8 @@ type Chat struct {
|
|||||||
Text string
|
Text string
|
||||||
Subject string
|
Subject string
|
||||||
Thread string
|
Thread string
|
||||||
|
Ooburl string
|
||||||
|
Oobdesc string
|
||||||
Roster Roster
|
Roster Roster
|
||||||
Other []string
|
Other []string
|
||||||
OtherElem []XMLElement
|
OtherElem []XMLElement
|
||||||
@@ -684,21 +686,44 @@ func (c *Client) Recv() (stanza interface{}, err error) {
|
|||||||
|
|
||||||
// Send sends the message wrapped inside an XMPP message stanza body.
|
// Send sends the message wrapped inside an XMPP message stanza body.
|
||||||
func (c *Client) Send(chat Chat) (n int, err error) {
|
func (c *Client) Send(chat Chat) (n int, err error) {
|
||||||
var subtext = ``
|
var subtext, thdtext, oobtext string
|
||||||
var thdtext = ``
|
|
||||||
if chat.Subject != `` {
|
if chat.Subject != `` {
|
||||||
subtext = `<subject>` + xmlEscape(chat.Subject) + `</subject>`
|
subtext = `<subject>` + xmlEscape(chat.Subject) + `</subject>`
|
||||||
}
|
}
|
||||||
if chat.Thread != `` {
|
if chat.Thread != `` {
|
||||||
thdtext = `<thread>` + xmlEscape(chat.Thread) + `</thread>`
|
thdtext = `<thread>` + xmlEscape(chat.Thread) + `</thread>`
|
||||||
}
|
}
|
||||||
|
if chat.Ooburl != `` {
|
||||||
|
oobtext = `<x xmlns="jabber:x:oob"><url>` + xmlEscape(chat.Ooburl) + `</url>`
|
||||||
|
if chat.Oobdesc != `` {
|
||||||
|
oobtext += `<desc>` + xmlEscape(chat.Oobdesc) + `</desc>`
|
||||||
|
}
|
||||||
|
oobtext += `</x>`
|
||||||
|
}
|
||||||
|
|
||||||
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + thdtext + "</message>"
|
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + oobtext + thdtext + "</message>"
|
||||||
|
|
||||||
return fmt.Fprintf(c.conn, stanza,
|
return fmt.Fprintf(c.conn, stanza,
|
||||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text))
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendOOB sends OOB data wrapped inside an XMPP message stanza, without actual body.
|
||||||
|
func (c *Client) SendOOB(chat Chat) (n int, err error) {
|
||||||
|
var thdtext, oobtext string
|
||||||
|
if chat.Thread != `` {
|
||||||
|
thdtext = `<thread>` + xmlEscape(chat.Thread) + `</thread>`
|
||||||
|
}
|
||||||
|
if chat.Ooburl != `` {
|
||||||
|
oobtext = `<x xmlns="jabber:x:oob"><url>` + xmlEscape(chat.Ooburl) + `</url>`
|
||||||
|
if chat.Oobdesc != `` {
|
||||||
|
oobtext += `<desc>` + xmlEscape(chat.Oobdesc) + `</desc>`
|
||||||
|
}
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
|
||||||
// SendOrg sends the original text without being wrapped in an XMPP message stanza.
|
// SendOrg sends the original text without being wrapped in an XMPP message stanza.
|
||||||
func (c *Client) SendOrg(org string) (n int, err error) {
|
func (c *Client) SendOrg(org string) (n int, err error) {
|
||||||
return fmt.Fprint(c.conn, org)
|
return fmt.Fprint(c.conn, org)
|
||||||
|
|||||||
Reference in New Issue
Block a user