--- a/xmpp/roster.go Sat Sep 07 10:30:22 2013 -0700
+++ b/xmpp/roster.go Sat Sep 07 11:19:29 2013 -0700
@@ -8,6 +8,7 @@
import (
"encoding/xml"
+ "reflect"
)
// Roster query/result
@@ -32,9 +33,9 @@
type Roster struct {
Extension
- get chan []RosterItem
+ get chan []RosterItem
callbacks chan rosterCb
- toServer chan Stanza
+ toServer chan Stanza
}
type rosterClient struct {
@@ -42,23 +43,18 @@
rosterUpdate chan<- RosterItem
}
-// Implicitly becomes part of NewClient's extStanza arg.
-func newRosterQuery(name *xml.Name) interface{} {
- return &RosterQuery{}
-}
-
func (r *Roster) rosterMgr(upd <-chan Stanza) {
roster := make(map[string]RosterItem)
waits := make(map[string]func())
var snapshot []RosterItem
for {
select {
- case stan, ok := <- upd:
+ case stan, ok := <-upd:
if !ok {
return
}
hdr := stan.GetHeader()
- if f := waits[hdr.Id] ; f != nil {
+ if f := waits[hdr.Id]; f != nil {
delete(waits, hdr.Id)
f()
}
@@ -84,7 +80,7 @@
snapshot = append(snapshot, ri)
}
case r.get <- snapshot:
- case cb := <- r.callbacks:
+ case cb := <-r.callbacks:
waits[cb.id] = cb.cb
}
}
@@ -104,12 +100,12 @@
defer close(out)
for {
select {
- case stan, ok := <- in:
+ case stan, ok := <-in:
if !ok {
return
}
out <- stan
- case stan := <- r.toServer:
+ case stan := <-r.toServer:
out <- stan
}
}
@@ -119,8 +115,9 @@
func newRosterExt() *Roster {
r := Roster{}
- r.StanzaHandlers = make(map[string]func(*xml.Name) interface{})
- r.StanzaHandlers[NsRoster] = newRosterQuery
+ r.StanzaHandlers = make(map[xml.Name]reflect.Type)
+ rName := xml.Name{Space: NsRoster, Local: "query"}
+ r.StanzaHandlers[rName] = reflect.TypeOf(RosterQuery{})
r.RecvFilter, r.SendFilter = r.makeFilters()
r.get = make(chan []RosterItem)
r.callbacks = make(chan rosterCb)