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

7
main
View File

@ -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/<roomid>")
@limiter.exempt
def chatget(roomid):
messages = get_messages(roomid)
messages = get_messages(roomid, 40)
template = []

View File

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

View File

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