def index(): session["room"] = None form = RoomCreateForm() if form.validate_on_submit(): room_id = rc.incr(app.config["ROOM_INCR_KEY"]) rc.set( app.config["ROOM_INFO_KEY"].format(room=room_id), json.dumps({ "title": form.title.data, "room_id": room_id, "creator": current_user.username, "created": datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y") })) flash("New room has already been created successfully!") return redirect("/room/" + str(room_id)) rooms = [] room_info_keys = app.config["ROOM_INFO_KEY"].format(room='*') for room_info_key in rc.keys(room_info_keys): room_info = json.loads(rc.get(room_info_key)) rooms.append({ "id": room_info["room_id"], "creator": room_info["creator"], "title": room_info["title"], "time": room_info["created"] }) return render_template("index.html", form=form, rooms=rooms)
def on_new_message(message): data = {"user": current_user.username, "content": excape_text(message["data"]), "created": datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), "room_id": session["room"], "id":rc.incr(app.config["ROOM_CONTENT_INCR_KEY"]) } rc.zadd(app.config["ROOM_ONLINE_USER_CHANNEL"].format(room=session["room"]), json.dumps(data), time.time()) emit("new_message", { "user": current_user.username, "time": datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), "data": excape_text(message["data"]) }, room=session["room"])
def on_new_message(message): data = { "user": current_user.username, "content": excape_text(message["data"]), "created": datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), "room_id": session["room"], "id": rc.incr(app.config["ROOM_CONTENT_INCR_KEY"]) } rc.zadd( app.config["ROOM_ONLINE_USER_CHANNEL"].format(room=session["room"]), json.dumps(data), time.time()) emit("new_message", { "user": current_user.username, "time": datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), "data": excape_text(message["data"]) }, room=session["room"])
def index(): session["room"] = None form = RoomCreateForm() if form.validate_on_submit(): room_id = rc.incr(app.config["ROOM_INCR_KEY"]) rc.set(app.config["ROOM_INFO_KEY"].format(room=room_id), json.dumps({"title": form.title.data, "room_id": room_id, "creator": current_user.username, "created": datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y") })) flash("New room has already been created successfully!") return redirect("/room/"+str(room_id)) rooms = [] room_info_keys = app.config["ROOM_INFO_KEY"].format(room='*') for room_info_key in rc.keys(room_info_keys): room_info = json.loads(rc.get(room_info_key)) rooms.append({ "id": room_info["room_id"], "creator": room_info["creator"], "title": room_info["title"], "time": room_info["created"] }) return render_template("index.html", form=form, rooms=rooms)