improvements

This commit is contained in:
maaa 2023-07-12 02:24:51 +02:00
parent 0d5a1028ae
commit 7c4c0c7ceb
3 changed files with 11 additions and 8 deletions

9
main
View File

@ -82,10 +82,10 @@ def get_comments(id):
return post return post
def get_messages(chatroomid): def get_messages(chatroomid, max):
conn = get_db_connection() conn = get_db_connection()
post = conn.execute("SELECT * FROM chatmessages WHERE chatroom_id = ? ORDER BY created DESC;", post = conn.execute("SELECT * FROM chatmessages WHERE chatroom_id = ? ORDER BY created DESC;",
(chatroomid,)).fetchall() (chatroomid,)).fetchmany(max + 1)
conn.close() conn.close()
if post is None: if post is None:
return "error" return "error"
@ -176,8 +176,9 @@ def chatlistrooms():
return(template), 200 return(template), 200
@app.route("/api/chat/getmessages/<roomid>") @app.route("/api/chat/getmessages/<roomid>")
@limiter.exempt
def chatget(roomid): def chatget(roomid):
messages = get_messages(roomid) messages = get_messages(roomid, 40)
template = [] template = []
@ -749,4 +750,4 @@ if __name__ == "__main__":
sock.bind(('', int(PORT))) sock.bind(('', int(PORT)))
serve(app, sockets=[sock]) serve(app, sockets=[sock])
print("[INFO] Server stopped") print("[INFO] Server stopped")

View File

@ -73,9 +73,11 @@ async function sendMessage(content, id) {
messageBox.addEventListener("keyup", function onEvent(event) { messageBox.addEventListener("keyup", function onEvent(event) {
if (event.key === "Enter") { if (event.key === "Enter") {
if (!messageBox.value == "") { if (!messageBox.value == "") {
sendMessage(messageBox.value, channelID) if (messageBox.value.length < 140) {
updateMessages(channelID) sendMessage(messageBox.value, channelID)
messageBox.value = "" updateMessages(channelID)
messageBox.value = ""
}
} }
} }
}) })

View File

@ -40,7 +40,7 @@
<div class="chatDiv"> <div class="chatDiv">
<div id="channelDiv" class="channelDiv"> <div id="channelDiv" class="channelDiv">
<p class="statusMessage" id="statusMessage">Connected</p> <p class="statusMessage" id="statusMessage">Connecting..</p>
</div> </div>
<div id="messageDiv" class="messageDiv"> <div id="messageDiv" class="messageDiv">
</div> </div>