Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions xmpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ func (c *Client) IsEncrypted() bool {

// Chat is an incoming or outgoing XMPP chat message.
type Chat struct {
ID string
Remote string
Type string
Text string
Expand All @@ -1465,7 +1466,11 @@ type Chat struct {
// Only for incoming messages, ID for outgoing messages will be generated.
OriginID string
// Only for incoming messages, ID for outgoing messages will be generated.
StanzaID StanzaID
StanzaID StanzaID
// XEP-0461: id of the message being replied to (use StanzaID for groupchat)
ReplyID string
// XEP-0461: JID of the author of the message being replied to
ReplyTo string
Roster Roster
Other []string
OtherElem []XMLElement
Expand Down Expand Up @@ -1550,6 +1555,7 @@ func (c *Client) Recv() (stanza interface{}, err error) {
v.Delay.Stamp,
)
chat := Chat{
ID: v.ID,
Remote: v.From,
Type: v.Type,
Text: v.Body,
Expand All @@ -1561,6 +1567,8 @@ func (c *Client) Recv() (stanza interface{}, err error) {
Lang: v.Lang,
OriginID: v.OriginID.ID,
StanzaID: v.StanzaID,
ReplyID: v.Reply.ID,
ReplyTo: v.Reply.To,
Oob: v.Oob,
}
return chat, nil
Expand Down Expand Up @@ -1852,10 +1860,22 @@ func (c *Client) Send(chat Chat) (n int, err error) {
oobtext += `</x>`
}

var replytext string
if chat.ReplyID != `` {
replytext = `<reply id='` + xmlEscape(chat.ReplyID) + `'`
if chat.ReplyTo != `` {
replytext += ` to='` + xmlEscape(chat.ReplyTo) + `'`
}
replytext += ` xmlns='urn:xmpp:reply:0'/>`
}

chat.Text = validUTF8(chat.Text)
id := getUUID()
id := chat.ID
if id == "" {
id = getUUID()
}
stanza := fmt.Sprintf("<message to='%s' type='%s' id='%s' xml:lang='en'>%s<body>%s</body>"+
"<origin-id xmlns='%s' id='%s'/>%s%s</message>\n",
replytext+"<origin-id xmlns='%s' id='%s'/>%s%s</message>\n",
xmlEscape(chat.Remote), xmlEscape(chat.Type), id, subtext, xmlEscape(chat.Text),
XMPPNS_SID_0, id, oobtext, thdtext)
if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes {
Expand Down Expand Up @@ -2166,6 +2186,13 @@ type StanzaID struct {
By string `xml:"by,attr"`
}

// XEP-0461 Message Replies
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"`
Expand All @@ -2184,6 +2211,9 @@ type clientMessage struct {
OriginID originID `xml:"origin-id"`
StanzaID StanzaID `xml:"stanza-id"`

// XEP-0461
Reply clientReply `xml:"reply"`

// Pubsub
Event clientPubsubEvent `xml:"event"`

Expand Down