def quit(): # Only send a message if we were already online. if g.user_id is None or "chat_id" not in request.form: abort(400) try: g.chat_id = int(request.form["chat_id"]) except ValueError: abort(400) if disconnect(g.redis, g.chat_id, g.session_id): db_connect() get_chat_user() send_quit_message(g.db, g.redis, g.chat_user, g.user, g.chat) return "", 204
def on_close(self): # Unsubscribe here and let the exit callback handle disconnecting. if hasattr(self, "redis_client"): self.redis_client.unsubscribe(self.redis_client.subscribed) if self.joined and disconnect(redis, self.chat_id, self.id): try: send_quit_message(self.db, redis, *self.get_chat_user()) except NoResultFound: send_userlist(self.db, redis, self.chat) self.db.commit() self.set_typing(False) print "socket closed:", self.id redis.srem("chat:%s:sockets:%s" % (self.chat_id, self.session_id), self.id) sockets.remove(self)