roster.go
changeset 47 22e575eff35a
parent 46 4a4530b8f622
child 50 08d2b9deb710
equal deleted inserted replaced
46:4a4530b8f622 47:22e575eff35a
    99 			}
    99 			}
   100 		}
   100 		}
   101 	}(in, out)
   101 	}(in, out)
   102 }
   102 }
   103 
   103 
       
   104 // BUG(cjyar) This isn't actually thread safe, though it's unlikely it
       
   105 // will fail in practice. Either the roster should be protected with a
       
   106 // mutex, or we should make the roster available on a channel instead
       
   107 // of via a method call.
   104 func (cl *Client) maybeUpdateRoster(st Stanza) {
   108 func (cl *Client) maybeUpdateRoster(st Stanza) {
   105 	rq, ok := st.GetNested().(*RosterQuery)
   109 	rq, ok := st.GetNested().(*RosterQuery)
   106 	if st.GetName() == "iq" && st.GetType() == "set" && ok {
   110 	if st.GetName() == "iq" && st.GetType() == "set" && ok {
   107 		for _, item := range(rq.Item) {
   111 		for _, item := range(rq.Item) {
   108 			cl.roster[item.Jid] = &item
   112 			if item.Subscription == "remove" {
       
   113 				cl.roster[item.Jid] = nil
       
   114 			} else {
       
   115 				cl.roster[item.Jid] = &item
       
   116 			}
   109 		}
   117 		}
   110 	}
   118 	}
   111 }
   119 }