Implemented roster item delete, and added another BUG comment.
authorChris Jones <chris@cjones.org>
Sun, 01 Jan 2012 20:00:43 -0700
changeset 47 22e575eff35a
parent 46 4a4530b8f622
child 48 6b402eb552f5
Implemented roster item delete, and added another BUG comment.
roster.go
--- a/roster.go	Sun Jan 01 19:32:51 2012 -0700
+++ b/roster.go	Sun Jan 01 20:00:43 2012 -0700
@@ -101,11 +101,19 @@
 	}(in, out)
 }
 
+// BUG(cjyar) This isn't actually thread safe, though it's unlikely it
+// will fail in practice. Either the roster should be protected with a
+// mutex, or we should make the roster available on a channel instead
+// of via a method call.
 func (cl *Client) maybeUpdateRoster(st Stanza) {
 	rq, ok := st.GetNested().(*RosterQuery)
 	if st.GetName() == "iq" && st.GetType() == "set" && ok {
 		for _, item := range(rq.Item) {
-			cl.roster[item.Jid] = &item
+			if item.Subscription == "remove" {
+				cl.roster[item.Jid] = nil
+			} else {
+				cl.roster[item.Jid] = &item
+			}
 		}
 	}
 }