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,11 +73,13 @@ 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 == "") {
|
||||||
|
if (messageBox.value.length < 140) {
|
||||||
sendMessage(messageBox.value, channelID)
|
sendMessage(messageBox.value, channelID)
|
||||||
updateMessages(channelID)
|
updateMessages(channelID)
|
||||||
messageBox.value = ""
|
messageBox.value = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
|
|
|
@ -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