improvements
This commit is contained in:
parent
0d5a1028ae
commit
7c4c0c7ceb
7
main
7
main
|
@ -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 = []
|
||||||
|
|
||||||
|
|
|
@ -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 = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Reference in New Issue