mitsuhiko/python-juggernaut — pull request #1 by mmlin (2012-06-22 06:30:44+00:00)
Title: RedisRoster not calling on_signed_in event, and not removing offline users

Hello mitsuhiko. These are just a couple small fixes for the `RedisRoster` implementation. No API changes.

I hope this helps. Great job by the way. It was really fun playing with this, and it's great to be able to use socket.io so easily with my Python apps.

### `on_signed_in()` was never being called

In `on_subcribe()`, we check add a new session for the user. Afterwards, we check to see if that session was the first for that `user_id`. If so, we call `on_signed_in()`. The problem is that we whether the set is empty immediately after adding an entry--so it will never be.

r.sadd(key, data['session_id'])
if r.scard(key) == 0: # at first sign-in, this should be one, not zero
self.on_signed_in(user_id)

We should really be checking whether there's exactly one entry, which indicates this was the first session added for that user.

### The user wasn't being removed from set `juggernaut-roster:online-users`

This looks like a typo. Instead of removing the user from the set, we are attempting to add him instead.

r.srem(key, data['session_id'])
if r.scard(key) == 0:
self.on_signed_out(user_id)
r.sadd(self.key_prefix + 'online-users', user_id) # we should remove insead of add here