def reaction(handler, f_status_change): user = users.User(email = handler.request.get("from")) q = UserOnline.all().filter("user ="******"type": "onlineStatus", "uid": MyUser.create(user.email()).id, "on": model.online, } if model.online: message["nickname"] = user.nickname() json_msg = json.dumps(message) q = UserOnline.get_online_list() #Update the list of online user in memcache for others to use online_list = q.fetch(20) if memcache.get("online_list") == None: if not memcache.add("online_list", online_list): raise Warning("memcache add doens't work") else: memcache.set("online_list", online_list) for item in q: if user.email() != item.user.email(): logging.info("Send msg to: "+item.user.email()+"; "+json_msg) channel.send_message(item.user.email(), json_msg)
def get(self): user = users.get_current_user() config = { "height": 500, "nmessage": 30, #The number of chat messages in history displayed to the client at first } values = { "user": user, "online_list": UserOnline.get_online_list(), "config": config, } values2 = {} if user: common.user_bootstrap(user) token = channel.create_channel(user.email()) q = db.GqlQuery("SELECT * FROM ChatMessage ORDER BY when_created DESC LIMIT %s" % config["nmessage"]) messages = [] for msg in q: messages.append({ "time": self.simple_time_str(msg.when_created), "nickname": msg.nickname, "content": msg.content, }) json_messages = json.dumps(messages) values2 = { "token": token, "logout_url": users.create_logout_url("/chatbox"), "messages": json_messages, "online_list": UserOnline.get_online_list(), } else: values2 = { "login_url": users.create_login_url("/chatbox"), } values.update(values2) self.response.out.write(common.render_template("chatbox.html", values))
def get(self): user = users.get_current_user() if user: common.user_bootstrap(user) token = channel.create_channel(user.email()) values = { "user": user, "token": token, "online_list": UserOnline.get_online_list(), } else: values = { "user": user, "login_url": users.create_login_url("/"), } self.response.out.write(common.render_template("mainpage.html", values))
def user_bootstrap(user): UserOnline.check_user(user) MyUser.check_user(user)