From 0c0c98633ce0f293cbecd38e0d46452a0f449454 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 16 Apr 2015 20:35:08 +0900 Subject: [PATCH] handle clientQuery --- xmpp.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/xmpp.go b/xmpp.go index 2012ce3..0fc7b70 100644 --- a/xmpp.go +++ b/xmpp.go @@ -513,9 +513,18 @@ type Chat struct { Remote string Type string Text string + Roster Roster Other []string } +type Roster []Contact + +type Contact struct { + Remote string + Name string + Group []string +} + // Presence is an XMPP presence notification. type Presence struct { From string @@ -534,7 +543,13 @@ func (c *Client) Recv() (stanza interface{}, err error) { } switch v := val.(type) { case *clientMessage: - return Chat{v.From, v.Type, v.Body, v.Other}, nil + return Chat{Remote: v.From, Type: v.Type, Text: v.Body, Other: v.Other}, nil + case *clientQuery: + var r Roster + for _, item := range v.Item { + r = append(r, Contact{item.Jid, item.Name, item.Group}) + } + return Chat{Type: "roster", Roster: r}, nil case *clientPresence: return Presence{v.From, v.To, v.Type, v.Show}, nil } @@ -687,6 +702,18 @@ type clientError struct { Text string } +type clientQuery struct { + Item []rosterItem +} + +type rosterItem struct { + XMLName xml.Name `xml:"jabber:iq:roster item"` + Jid string `xml:",attr"` + Name string `xml:",attr"` + Subscription string `xml:",attr"` + Group []string +} + // Scan XML token stream to find next StartElement. func nextStart(p *xml.Decoder) (xml.StartElement, error) { for {