improvements
This commit is contained in:
parent
0d5a1028ae
commit
7c4c0c7ceb
7
main
7
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/<roomid>")
|
||||
@limiter.exempt
|
||||
def chatget(roomid):
|
||||
messages = get_messages(roomid)
|
||||
messages = get_messages(roomid, 40)
|
||||
|
||||
template = []
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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>
|
||||
|
|
Reference in New Issue