roster.go
changeset 61 16513974d273
parent 60 6d4f43f7dc19
child 72 53f15893a1a7
equal deleted inserted replaced
60:6d4f43f7dc19 61:16513974d273
    50 // as part of XMPP negotiation.
    50 // as part of XMPP negotiation.
    51 func fetchRoster(client *Client) os.Error {
    51 func fetchRoster(client *Client) os.Error {
    52 	rosterUpdate := rosterClients[client.Uid].rosterUpdate
    52 	rosterUpdate := rosterClients[client.Uid].rosterUpdate
    53 
    53 
    54 	iq := &Iq{From: client.Jid.String(), Id: <- Id, Type: "get",
    54 	iq := &Iq{From: client.Jid.String(), Id: <- Id, Type: "get",
    55 		Nested: RosterQuery{}}
    55 		Nested: []interface{}{RosterQuery{}}}
    56 	ch := make(chan os.Error)
    56 	ch := make(chan os.Error)
    57 	f := func(st Stanza) bool {
    57 	f := func(st Stanza) bool {
    58 		defer close(ch)
    58 		defer close(ch)
    59 		if iq.Type == "error" {
    59 		if iq.Type == "error" {
    60 			ch <- iq.Error
    60 			ch <- iq.Error
    61 			return false
    61 			return false
    62 		}
    62 		}
    63 		rq, ok := st.GetNested().(*RosterQuery)
    63 		var rq *RosterQuery
    64 		if !ok {
    64 		for _, ele := range(st.GetNested()) {
       
    65 			if q, ok := ele.(*RosterQuery) ; ok {
       
    66 				rq = q
       
    67 				break
       
    68 			}
       
    69 		}
       
    70 		if rq == nil {
    65 			ch <- os.NewError(fmt.Sprintf(
    71 			ch <- os.NewError(fmt.Sprintf(
    66 				"Roster query result not query: %v", st))
    72 				"Roster query result not query: %v", st))
    67 			return false
    73 			return false
    68 		}
    74 		}
    69 		for _, item := range(rq.Item) {
    75 		for _, item := range(rq.Item) {
   101 }
   107 }
   102 
   108 
   103 func maybeUpdateRoster(client *Client, st Stanza) {
   109 func maybeUpdateRoster(client *Client, st Stanza) {
   104 	rosterUpdate := rosterClients[client.Uid].rosterUpdate
   110 	rosterUpdate := rosterClients[client.Uid].rosterUpdate
   105 
   111 
   106 	rq, ok := st.GetNested().(*RosterQuery)
   112 	var rq *RosterQuery
   107 	if st.GetName() == "iq" && st.GetType() == "set" && ok {
   113 	for _, ele := range(st.GetNested()) {
       
   114 		if q, ok := ele.(*RosterQuery) ; ok {
       
   115 			rq = q
       
   116 			break
       
   117 		}
       
   118 	}
       
   119 	if st.GetName() == "iq" && st.GetType() == "set" && rq != nil {
   108 		for _, item := range(rq.Item) {
   120 		for _, item := range(rq.Item) {
   109 			rosterUpdate <- item
   121 			rosterUpdate <- item
   110 		}
   122 		}
   111 		// Send a reply.
   123 		// Send a reply.
   112 		iq := &Iq{To: st.GetFrom(), Id: st.GetId(), Type:
   124 		iq := &Iq{To: st.GetFrom(), Id: st.GetId(), Type: