forked from jshiffer/go-xmpp
xmpp: Add reply and stanza ID serialization/deserialization
This commit is contained in:
parent
7154bfeb76
commit
370c500a5e
26
xmpp.go
26
xmpp.go
@ -1204,6 +1204,8 @@ type Chat struct {
|
||||
Lang string
|
||||
ID string
|
||||
ReplaceID string
|
||||
ReplyID string
|
||||
StanzaID string
|
||||
Roster Roster
|
||||
Other []string
|
||||
OtherElem []XMLElement
|
||||
@ -1286,6 +1288,8 @@ func (c *Client) Recv() (stanza interface{}, err error) {
|
||||
Thread: v.Thread,
|
||||
ID: v.ID,
|
||||
ReplaceID: v.ReplaceID.ID,
|
||||
ReplyID: v.ReplyID.ID,
|
||||
StanzaID: v.StanzaID.ID,
|
||||
Other: v.OtherStrings(),
|
||||
OtherElem: v.Other,
|
||||
Stamp: stamp,
|
||||
@ -1488,7 +1492,7 @@ 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, thdtext, oobtext, msgidtext, msgcorrecttext string
|
||||
var subtext, thdtext, oobtext, msgidtext, msgcorrecttext, replytext string
|
||||
if chat.Subject != `` {
|
||||
subtext = `<subject>` + xmlEscape(chat.Subject) + `</subject>`
|
||||
}
|
||||
@ -1512,9 +1516,13 @@ func (c *Client) Send(chat Chat) (n int, err error) {
|
||||
msgcorrecttext = `<replace id='` + xmlEscape(chat.ReplaceID) + `' xmlns='urn:xmpp:message-correct:0'/>`
|
||||
}
|
||||
|
||||
if chat.ReplyID != `` {
|
||||
replytext = `<reply to='`+ xmlEscape(chat.Remote) + `' id='` + xmlEscape(chat.ReplyID) + `' xmlns='urn:xmpp:reply:0'/>`
|
||||
}
|
||||
|
||||
chat.Text = validUTF8(chat.Text)
|
||||
|
||||
stanza := fmt.Sprintf("<message to='%s' type='%s' "+msgidtext+" xml:lang='en'>"+subtext+"<body>%s</body>"+msgcorrecttext+oobtext+thdtext+"</message>",
|
||||
stanza := fmt.Sprintf("<message to='%s' type='%s' "+msgidtext+" xml:lang='en'>"+subtext+"<body>%s</body>"+msgcorrecttext+replytext+oobtext+thdtext+"</message>",
|
||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||
|
||||
if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes {
|
||||
@ -1768,6 +1776,18 @@ type clientMessageCorrect struct {
|
||||
ID string `xml:"id,attr"`
|
||||
}
|
||||
|
||||
type stanzaID struct {
|
||||
XMLName xml.Name `xml:"urn:xmpp:sid:0 stanza-id"`
|
||||
ID string `xml:"id,attr"`
|
||||
By string `xml:"by,attr"`
|
||||
}
|
||||
|
||||
type clientReply struct {
|
||||
XMLName xml.Name `xml:"urn:xmpp:reply:0 reply"`
|
||||
ID string `xml:"id,attr"`
|
||||
To string `xml:"to,attr"`
|
||||
}
|
||||
|
||||
// RFC 3921 B.1 jabber:client
|
||||
type clientMessage struct {
|
||||
XMLName xml.Name `xml:"jabber:client message"`
|
||||
@ -1782,6 +1802,8 @@ type clientMessage struct {
|
||||
Body string `xml:"body"`
|
||||
Thread string `xml:"thread"`
|
||||
ReplaceID clientMessageCorrect
|
||||
StanzaID stanzaID
|
||||
ReplyID clientReply
|
||||
|
||||
// Pubsub
|
||||
Event clientPubsubEvent `xml:"event"`
|
||||
|
Loading…
Reference in New Issue
Block a user