roster.go
changeset 38 2839fece923e
parent 37 fbda8e925fdf
child 39 4a06f7ccfa84
--- a/roster.go	Sat Dec 31 10:11:01 2011 -0700
+++ b/roster.go	Sat Dec 31 11:39:23 2011 -0700
@@ -6,19 +6,12 @@
 
 import (
 	"fmt"
-	"io"
 	"os"
 	"xml"
 )
 
 // This file contains support for roster management, RFC 3921, Section 7.
 
-type RosterIq struct {
-	Iq
-	Query RosterQuery
-}
-var _ ExtendedStanza = &RosterIq{}
-
 // Roster query/result
 type RosterQuery struct {
 	// Should always be NsRoster, "query"
@@ -36,40 +29,31 @@
 	Group []string
 }
 
-func (riq *RosterIq) MarshalXML() ([]byte, os.Error) {
-	return marshalXML(riq)
-}
-
-func (riq *RosterIq) InnerMarshal(w io.Writer) os.Error {
-	return xml.Marshal(w, riq.Query)
-}
-
 // Implicitly becomes part of NewClient's extStanza arg.
-func rosterStanza(name *xml.Name) ExtendedStanza {
-	return &RosterIq{}
+func newRosterQuery(name *xml.Name) interface{} {
+	return &RosterQuery{}
 }
 
 // Synchronously fetch this entity's roster from the server and cache
 // that information.
 func (cl *Client) fetchRoster() os.Error {
-	iq := &RosterIq{Iq: Iq{From: cl.Jid.String(), Id: <- cl.Id,
-		Type: "get"}, Query: RosterQuery{XMLName:
-			xml.Name{Local: "query", Space: NsRoster}}}
+	iq := &Iq{From: cl.Jid.String(), Id: <- cl.Id, Type: "get",
+		Nested: RosterQuery{XMLName: xml.Name{Local: "query",
+			Space: NsRoster}}}
 	ch := make(chan os.Error)
 	f := func(st Stanza) bool {
-		iq, ok := st.(*RosterIq)
-		if !ok {
-			ch <- os.NewError(fmt.Sprintf(
-				"Roster query result not iq: %v", st))
-			return false
-		}
 		if iq.Type == "error" {
 			ch <- iq.Error
 			return false
 		}
-		q := iq.Query
-		cl.roster = make(map[string] *RosterItem, len(q.Item))
-		for _, item := range(q.Item) {
+		rq, ok := st.XNested().(*RosterQuery)
+		if !ok {
+			ch <- os.NewError(fmt.Sprintf(
+				"Roster query result not query: %v", st))
+			return false
+		}
+		cl.roster = make(map[string] *RosterItem, len(rq.Item))
+		for _, item := range(rq.Item) {
 			cl.roster[item.Jid] = &item
 		}
 		ch <- nil