diff --git a/main b/main index edb2e97..64a1f11 100644 --- a/main +++ b/main @@ -82,10 +82,10 @@ def get_comments(id): return post -def get_messages(chatroomid): +def get_messages(chatroomid, max): conn = get_db_connection() post = conn.execute("SELECT * FROM chatmessages WHERE chatroom_id = ? ORDER BY created DESC;", - (chatroomid,)).fetchall() + (chatroomid,)).fetchmany(max + 1) conn.close() if post is None: return "error" @@ -176,8 +176,9 @@ def chatlistrooms(): return(template), 200 @app.route("/api/chat/getmessages/") +@limiter.exempt def chatget(roomid): - messages = get_messages(roomid) + messages = get_messages(roomid, 40) template = [] @@ -749,4 +750,4 @@ if __name__ == "__main__": sock.bind(('', int(PORT))) serve(app, sockets=[sock]) - print("[INFO] Server stopped") + print("[INFO] Server stopped") \ No newline at end of file diff --git a/static/js/chat.js b/static/js/chat.js index 97ff2af..c3b2400 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -73,9 +73,11 @@ async function sendMessage(content, id) { messageBox.addEventListener("keyup", function onEvent(event) { if (event.key === "Enter") { if (!messageBox.value == "") { - sendMessage(messageBox.value, channelID) - updateMessages(channelID) - messageBox.value = "" + if (messageBox.value.length < 140) { + sendMessage(messageBox.value, channelID) + updateMessages(channelID) + messageBox.value = "" + } } } }) diff --git a/templates/chat.html b/templates/chat.html index 3d47796..e1d251e 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -40,7 +40,7 @@
-

Connected

+

Connecting..