Demo support for items browsing

This commit is contained in:
Mickael Remond 2018-01-26 11:40:59 +01:00
parent c451e3bc63
commit bb1621364a
No known key found for this signature in database
GPG key ID: E6F6045D79965AA3

View file

@ -31,9 +31,13 @@ func main() {
case *xmpp.DiscoInfo: case *xmpp.DiscoInfo:
fmt.Println("Disco Info") fmt.Println("Disco Info")
if p.Type == "get" { if p.Type == "get" {
DiscoResult(component, p.From, p.To, p.Id) DiscoResult(component, p.PacketAttrs, inner)
}
case *xmpp.DiscoItems:
fmt.Println("DiscoItems")
if p.Type == "get" {
DiscoItems(component, p.PacketAttrs, inner)
} }
default: default:
fmt.Println("ignoring iq packet", inner) fmt.Println("ignoring iq packet", inner)
xError := xmpp.Err{ xError := xmpp.Err{
@ -63,19 +67,40 @@ type MyComponent struct {
xmpp *xmpp.Component xmpp *xmpp.Component
} }
func DiscoResult(c MyComponent, from, to, id string) { func DiscoResult(c MyComponent, attrs xmpp.PacketAttrs, info *xmpp.DiscoInfo) {
iq := xmpp.NewIQ("result", to, from, id, "en") iq := xmpp.NewIQ("result", attrs.To, attrs.From, attrs.Id, "en")
payload := xmpp.DiscoInfo{ var identity xmpp.Identity
Identity: xmpp.Identity{ if info.Node == "" {
identity = xmpp.Identity{
Name: c.Name, Name: c.Name,
Category: c.Category, Category: c.Category,
Type: c.Type, Type: c.Type,
}, }
}
payload := xmpp.DiscoInfo{
Identity: identity,
Features: []xmpp.Feature{ Features: []xmpp.Feature{
{Var: "http://jabber.org/protocol/disco#info"}, {Var: "http://jabber.org/protocol/disco#info"},
{Var: "http://jabber.org/protocol/disco#item"}, {Var: "http://jabber.org/protocol/disco#item"},
}, },
} }
iq.AddPayload(&payload) iq.AddPayload(&payload)
c.xmpp.Send(iq)
}
func DiscoItems(c MyComponent, attrs xmpp.PacketAttrs, items *xmpp.DiscoItems) {
iq := xmpp.NewIQ("result", attrs.To, attrs.From, attrs.Id, "en")
var payload xmpp.DiscoItems
if items.Node == "" {
payload = xmpp.DiscoItems{
Items: []xmpp.DiscoItem{
{Name: "test node", JID: "facebook.localhost", Node: "node1"},
},
}
}
iq.AddPayload(&payload)
c.xmpp.Send(iq) c.xmpp.Send(iq)
} }