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
|
Remote string
|
||||||
Type string
|
Type string
|
||||||
Text string
|
Text string
|
||||||
|
Roster Roster
|
||||||
Other []string
|
Other []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Roster []Contact
|
||||||
|
|
||||||
|
type Contact struct {
|
||||||
|
Remote string
|
||||||
|
Name string
|
||||||
|
Group []string
|
||||||
|
}
|
||||||
|
|
||||||
// Presence is an XMPP presence notification.
|
// Presence is an XMPP presence notification.
|
||||||
type Presence struct {
|
type Presence struct {
|
||||||
From string
|
From string
|
||||||
@ -534,7 +543,13 @@ func (c *Client) Recv() (stanza interface{}, err error) {
|
|||||||
}
|
}
|
||||||
switch v := val.(type) {
|
switch v := val.(type) {
|
||||||
case *clientMessage:
|
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:
|
case *clientPresence:
|
||||||
return Presence{v.From, v.To, v.Type, v.Show}, nil
|
return Presence{v.From, v.To, v.Type, v.Show}, nil
|
||||||
}
|
}
|
||||||
@ -687,6 +702,18 @@ type clientError struct {
|
|||||||
Text string
|
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.
|
// Scan XML token stream to find next StartElement.
|
||||||
func nextStart(p *xml.Decoder) (xml.StartElement, error) {
|
func nextStart(p *xml.Decoder) (xml.StartElement, error) {
|
||||||
for {
|
for {
|
||||||
|
Loading…
Reference in New Issue
Block a user