roster.go
changeset 39 4a06f7ccfa84
parent 38 2839fece923e
child 42 f6bb47ca12f2
equal deleted inserted replaced
38:2839fece923e 39:4a06f7ccfa84
    12 
    12 
    13 // This file contains support for roster management, RFC 3921, Section 7.
    13 // This file contains support for roster management, RFC 3921, Section 7.
    14 
    14 
    15 // Roster query/result
    15 // Roster query/result
    16 type RosterQuery struct {
    16 type RosterQuery struct {
    17 	// Should always be NsRoster, "query"
    17 	XMLName xml.Name `xml:"jabber:iq:roster query"`
    18 	XMLName xml.Name
       
    19 	Item []RosterItem
    18 	Item []RosterItem
    20 }
    19 }
    21 
    20 
    22 // See RFC 3921, Section 7.1.
    21 // See RFC 3921, Section 7.1.
    23 type RosterItem struct {
    22 type RosterItem struct {
    24 	// Should always be "item"
    23 	XMLName xml.Name `xml:"item"`
    25 	XMLName xml.Name
       
    26 	Jid string `xml:"attr"`
    24 	Jid string `xml:"attr"`
    27 	Subscription string `xml:"attr"`
    25 	Subscription string `xml:"attr"`
    28 	Name string `xml:"attr"`
    26 	Name string `xml:"attr"`
    29 	Group []string
    27 	Group []string
    30 }
    28 }
    36 
    34 
    37 // Synchronously fetch this entity's roster from the server and cache
    35 // Synchronously fetch this entity's roster from the server and cache
    38 // that information.
    36 // that information.
    39 func (cl *Client) fetchRoster() os.Error {
    37 func (cl *Client) fetchRoster() os.Error {
    40 	iq := &Iq{From: cl.Jid.String(), Id: <- cl.Id, Type: "get",
    38 	iq := &Iq{From: cl.Jid.String(), Id: <- cl.Id, Type: "get",
    41 		Nested: RosterQuery{XMLName: xml.Name{Local: "query",
    39 		Nested: RosterQuery{}}
    42 			Space: NsRoster}}}
       
    43 	ch := make(chan os.Error)
    40 	ch := make(chan os.Error)
    44 	f := func(st Stanza) bool {
    41 	f := func(st Stanza) bool {
    45 		if iq.Type == "error" {
    42 		if iq.Type == "error" {
    46 			ch <- iq.Error
    43 			ch <- iq.Error
    47 			return false
    44 			return false