From 3e4868bd3e6c613bd85d7a0421c5de49fb1e92c8 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Mon, 9 Mar 2020 09:10:06 +0000 Subject: [PATCH] Implement OOB in Send() and add SendOOB() function for messages without body (#117) Co-authored-by: Qais Patankar Co-authored-by: ValdikSS --- xmpp.go | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/xmpp.go b/xmpp.go index dd7d81c..372aaf6 100644 --- a/xmpp.go +++ b/xmpp.go @@ -597,6 +597,8 @@ type Chat struct { Text string Subject string Thread string + Ooburl string + Oobdesc string Roster Roster Other []string 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. func (c *Client) Send(chat Chat) (n int, err error) { - var subtext = `` - var thdtext = `` + var subtext, thdtext, oobtext string if chat.Subject != `` { subtext = `` + xmlEscape(chat.Subject) + `` } if chat.Thread != `` { thdtext = `` + xmlEscape(chat.Thread) + `` } + if chat.Ooburl != `` { + oobtext = `` + xmlEscape(chat.Ooburl) + `` + if chat.Oobdesc != `` { + oobtext += `` + xmlEscape(chat.Oobdesc) + `` + } + oobtext += `` + } - stanza := "" + subtext + "%s" + thdtext + "" + stanza := "" + subtext + "%s" + oobtext + thdtext + "" return fmt.Fprintf(c.conn, stanza, 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 = `` + xmlEscape(chat.Thread) + `` + } + if chat.Ooburl != `` { + oobtext = `` + xmlEscape(chat.Ooburl) + `` + if chat.Oobdesc != `` { + oobtext += `` + xmlEscape(chat.Oobdesc) + `` + } + oobtext += `` + } + return fmt.Fprintf(c.conn, ""+oobtext+thdtext+"", + xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce()) +} + // SendOrg sends the original text without being wrapped in an XMPP message stanza. func (c *Client) SendOrg(org string) (n int, err error) { return fmt.Fprint(c.conn, org)