forked from jshiffer/go-xmpp
handle clientQuery
This commit is contained in:
parent
861872c8db
commit
0c0c98633c
29
xmpp.go
29
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user