forked from jshiffer/go-xmpp
Implement XMPP message ID and message correction functionality
This commit is contained in:
parent
e9123cc4b3
commit
243a438354
33
xmpp.go
33
xmpp.go
@ -1202,6 +1202,8 @@ type Chat struct {
|
|||||||
Ooburl string
|
Ooburl string
|
||||||
Oobdesc string
|
Oobdesc string
|
||||||
Lang string
|
Lang string
|
||||||
|
ID string
|
||||||
|
ReplaceID string
|
||||||
Roster Roster
|
Roster Roster
|
||||||
Other []string
|
Other []string
|
||||||
OtherElem []XMLElement
|
OtherElem []XMLElement
|
||||||
@ -1282,6 +1284,8 @@ func (c *Client) Recv() (stanza interface{}, err error) {
|
|||||||
Text: v.Body,
|
Text: v.Body,
|
||||||
Subject: v.Subject,
|
Subject: v.Subject,
|
||||||
Thread: v.Thread,
|
Thread: v.Thread,
|
||||||
|
ID: v.ID,
|
||||||
|
ReplaceID: v.ReplaceID.ID,
|
||||||
Other: v.OtherStrings(),
|
Other: v.OtherStrings(),
|
||||||
OtherElem: v.Other,
|
OtherElem: v.Other,
|
||||||
Stamp: stamp,
|
Stamp: stamp,
|
||||||
@ -1484,7 +1488,7 @@ 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, thdtext, oobtext string
|
var subtext, thdtext, oobtext, msgidtext, msgcorrecttext string
|
||||||
if chat.Subject != `` {
|
if chat.Subject != `` {
|
||||||
subtext = `<subject>` + xmlEscape(chat.Subject) + `</subject>`
|
subtext = `<subject>` + xmlEscape(chat.Subject) + `</subject>`
|
||||||
}
|
}
|
||||||
@ -1498,10 +1502,21 @@ func (c *Client) Send(chat Chat) (n int, err error) {
|
|||||||
}
|
}
|
||||||
oobtext += `</x>`
|
oobtext += `</x>`
|
||||||
}
|
}
|
||||||
|
if chat.ID != `` {
|
||||||
|
msgidtext = `id='` + xmlEscape(chat.ID) + `'`
|
||||||
|
} else {
|
||||||
|
msgidtext = `id='` + cnonce() + `'`
|
||||||
|
}
|
||||||
|
|
||||||
|
if chat.ReplaceID != `` {
|
||||||
|
msgcorrecttext = `<replace id='` + xmlEscape(chat.ReplaceID) + `' xmlns='urn:xmpp:message-correct:0'/>`
|
||||||
|
}
|
||||||
|
|
||||||
chat.Text = validUTF8(chat.Text)
|
chat.Text = validUTF8(chat.Text)
|
||||||
stanza := fmt.Sprintf("<message to='%s' type='%s' id='%s' xml:lang='en'>"+subtext+"<body>%s</body>"+oobtext+thdtext+"</message>\n",
|
|
||||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text))
|
stanza := fmt.Sprintf("<message to='%s' type='%s' "+msgidtext+" xml:lang='en'>"+subtext+"<body>%s</body>"+msgcorrecttext+oobtext+thdtext+"</message>",
|
||||||
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||||
|
|
||||||
if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes {
|
if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes {
|
||||||
return 0, fmt.Errorf("stanza size (%v bytes) exceeds server limit (%v bytes)",
|
return 0, fmt.Errorf("stanza size (%v bytes) exceeds server limit (%v bytes)",
|
||||||
len(stanza), c.LimitMaxBytes)
|
len(stanza), c.LimitMaxBytes)
|
||||||
@ -1748,6 +1763,11 @@ type bindBind struct {
|
|||||||
Jid string `xml:"jid"`
|
Jid string `xml:"jid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type clientMessageCorrect struct {
|
||||||
|
XMLName xml.Name `xml:"urn:xmpp:message-correct:0 replace"`
|
||||||
|
ID string `xml:"id,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
// RFC 3921 B.1 jabber:client
|
// RFC 3921 B.1 jabber:client
|
||||||
type clientMessage struct {
|
type clientMessage struct {
|
||||||
XMLName xml.Name `xml:"jabber:client message"`
|
XMLName xml.Name `xml:"jabber:client message"`
|
||||||
@ -1758,9 +1778,10 @@ type clientMessage struct {
|
|||||||
Lang string `xml:"lang,attr"`
|
Lang string `xml:"lang,attr"`
|
||||||
|
|
||||||
// These should technically be []clientText, but string is much more convenient.
|
// These should technically be []clientText, but string is much more convenient.
|
||||||
Subject string `xml:"subject"`
|
Subject string `xml:"subject"`
|
||||||
Body string `xml:"body"`
|
Body string `xml:"body"`
|
||||||
Thread string `xml:"thread"`
|
Thread string `xml:"thread"`
|
||||||
|
ReplaceID clientMessageCorrect
|
||||||
|
|
||||||
// Pubsub
|
// Pubsub
|
||||||
Event clientPubsubEvent `xml:"event"`
|
Event clientPubsubEvent `xml:"event"`
|
||||||
|
Loading…
Reference in New Issue
Block a user