def room(room_id): room_online_user_channel = app.config["ROOM_ONLINE_USER_CHANNEL"].format( room=room_id) room_content_channel = app.config["ROOM_CONTENT_CHANNEL"].format( room=room_id) room_info_key = app.config["ROOM_INFO_KEY"].format(room=room_id) if session["room"] is not None: session["room"] = None rc.zrem(room_online_user_channel, current_user.username) session["room"] = str(room_id) rc.zadd(room_online_user_channel, current_user.username, time.time()) room_info = json.loads(rc.get(room_info_key)) room_content = reversed( rc.zrevrange(room_content_channel, 0, 200, withscores=True)) room_content_list = [] for item in room_content: room_content_list.append(json.loads(item[0])) room_online_users = [] for user in rc.zrange(room_online_user_channel, 0, -1): room_online_users.append(user) return render_template("room.html", room_id=room_id, room_info=room_info, users=room_online_users, user_name=current_user.username, messages=room_content_list)
def room(room_id): room_online_user_channel = app.config["ROOM_ONLINE_USER_CHANNEL"].format(room=room_id) room_content_channel = app.config["ROOM_CONTENT_CHANNEL"].format(room=room_id) room_info_key = app.config["ROOM_INFO_KEY"].format(room=room_id) if session["room"] is not None: session["room"] = None rc.zrem(room_online_user_channel, current_user.username) session["room"] = str(room_id) rc.zadd(room_online_user_channel, current_user.username, time.time()) room_info = json.loads(rc.get(room_info_key)) room_content = reversed(rc.zrevrange(room_content_channel, 0, 200, withscores=True)) room_content_list = [] for item in room_content: room_content_list.append(json.loads(item[0])) room_online_users =[] for user in rc.zrange(room_online_user_channel, 0, -1): room_online_users.append(user) return render_template("room.html", room_id=room_id, room_info=room_info, users=room_online_users, user_name=current_user.username, messages=room_content_list)
def on_leave_room(data): leave_room(session["room"]) session["room"] = None rc.zrem( app.config["ROOM_ONLINE_USER_CHANNEL"].format(room=session["room"]), current_user.username) redirect(url_for("index"))
def on_leave_room(data): leave_room(session["room"]) session["room"] = None rc.zrem(app.config["ROOM_ONLINE_USER_CHANNEL"].format(room=session["room"]), current_user.username) redirect(url_for("index"))