equal
deleted
inserted
replaced
14 } |
14 } |
15 |
15 |
16 // See RFC 3921, Section 7.1. |
16 // See RFC 3921, Section 7.1. |
17 type RosterItem struct { |
17 type RosterItem struct { |
18 XMLName xml.Name `xml:"jabber:iq:roster item"` |
18 XMLName xml.Name `xml:"jabber:iq:roster item"` |
19 Jid string `xml:"jid,attr"` |
19 Jid JID `xml:"jid,attr"` |
20 Subscription string `xml:"subscription,attr"` |
20 Subscription string `xml:"subscription,attr"` |
21 Name string `xml:"name,attr"` |
21 Name string `xml:"name,attr"` |
22 Group []string |
22 Group []string |
23 } |
23 } |
24 |
24 |
32 rosterChan <-chan []RosterItem |
32 rosterChan <-chan []RosterItem |
33 rosterUpdate chan<- RosterItem |
33 rosterUpdate chan<- RosterItem |
34 } |
34 } |
35 |
35 |
36 func (r *Roster) rosterMgr(upd <-chan Stanza) { |
36 func (r *Roster) rosterMgr(upd <-chan Stanza) { |
37 roster := make(map[string]RosterItem) |
37 roster := make(map[JID]RosterItem) |
38 var snapshot []RosterItem |
38 var snapshot []RosterItem |
39 var get chan<- []RosterItem |
39 var get chan<- []RosterItem |
40 for { |
40 for { |
41 select { |
41 select { |
42 case get <- snapshot: |
42 case get <- snapshot: |
77 func (r *Roster) makeFilters() (Filter, Filter) { |
77 func (r *Roster) makeFilters() (Filter, Filter) { |
78 rosterUpdate := make(chan Stanza) |
78 rosterUpdate := make(chan Stanza) |
79 go r.rosterMgr(rosterUpdate) |
79 go r.rosterMgr(rosterUpdate) |
80 recv := func(in <-chan Stanza, out chan<- Stanza) { |
80 recv := func(in <-chan Stanza, out chan<- Stanza) { |
81 defer close(out) |
81 defer close(out) |
|
82 defer close(rosterUpdate) |
82 for stan := range in { |
83 for stan := range in { |
83 rosterUpdate <- stan |
84 rosterUpdate <- stan |
84 out <- stan |
85 out <- stan |
85 } |
86 } |
86 } |
87 } |
101 return recv, send |
102 return recv, send |
102 } |
103 } |
103 |
104 |
104 func newRosterExt() *Roster { |
105 func newRosterExt() *Roster { |
105 r := Roster{} |
106 r := Roster{} |
106 r.StanzaHandlers = make(map[xml.Name]reflect.Type) |
107 r.StanzaTypes = make(map[xml.Name]reflect.Type) |
107 rName := xml.Name{Space: NsRoster, Local: "query"} |
108 rName := xml.Name{Space: NsRoster, Local: "query"} |
108 r.StanzaHandlers[rName] = reflect.TypeOf(RosterQuery{}) |
109 r.StanzaTypes[rName] = reflect.TypeOf(RosterQuery{}) |
109 r.RecvFilter, r.SendFilter = r.makeFilters() |
110 r.RecvFilter, r.SendFilter = r.makeFilters() |
110 r.get = make(chan []RosterItem) |
111 r.get = make(chan []RosterItem) |
111 r.toServer = make(chan Stanza) |
112 r.toServer = make(chan Stanza) |
112 return &r |
113 return &r |
113 } |
114 } |