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
|
||||
Oobdesc string
|
||||
Lang string
|
||||
ID string
|
||||
ReplaceID string
|
||||
Roster Roster
|
||||
Other []string
|
||||
OtherElem []XMLElement
|
||||
@ -1282,6 +1284,8 @@ func (c *Client) Recv() (stanza interface{}, err error) {
|
||||
Text: v.Body,
|
||||
Subject: v.Subject,
|
||||
Thread: v.Thread,
|
||||
ID: v.ID,
|
||||
ReplaceID: v.ReplaceID.ID,
|
||||
Other: v.OtherStrings(),
|
||||
OtherElem: v.Other,
|
||||
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.
|
||||
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 != `` {
|
||||
subtext = `<subject>` + xmlEscape(chat.Subject) + `</subject>`
|
||||
}
|
||||
@ -1498,10 +1502,21 @@ func (c *Client) Send(chat Chat) (n int, err error) {
|
||||
}
|
||||
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)
|
||||
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 {
|
||||
return 0, fmt.Errorf("stanza size (%v bytes) exceeds server limit (%v bytes)",
|
||||
len(stanza), c.LimitMaxBytes)
|
||||
@ -1748,6 +1763,11 @@ type bindBind struct {
|
||||
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
|
||||
type clientMessage struct {
|
||||
XMLName xml.Name `xml:"jabber:client message"`
|
||||
@ -1758,9 +1778,10 @@ type clientMessage struct {
|
||||
Lang string `xml:"lang,attr"`
|
||||
|
||||
// These should technically be []clientText, but string is much more convenient.
|
||||
Subject string `xml:"subject"`
|
||||
Body string `xml:"body"`
|
||||
Thread string `xml:"thread"`
|
||||
Subject string `xml:"subject"`
|
||||
Body string `xml:"body"`
|
||||
Thread string `xml:"thread"`
|
||||
ReplaceID clientMessageCorrect
|
||||
|
||||
// Pubsub
|
||||
Event clientPubsubEvent `xml:"event"`
|
||||
|
Loading…
Reference in New Issue
Block a user