mirror of
https://github.com/lucaspalomodevelop/Party.git
synced 2026-03-13 08:09:37 +00:00
init chat before starting server so it doesn't check wether it has been inited everytime chat is called
This commit is contained in:
parent
c19d4df58c
commit
2af8d34729
@ -22,6 +22,12 @@ class Chat:
|
||||
def insertMessage(self, content: str, author: str, timestamp: str):
|
||||
self.collection.insert_one(self.convertToMessage(content, author, timestamp))
|
||||
|
||||
@classmethod
|
||||
def getNext100Messages(self, skip: int) -> list[dict]:
|
||||
return list(self.collection.find()
|
||||
.skip(skip)
|
||||
.limit(100))
|
||||
|
||||
@classmethod
|
||||
def convertToMessage(self, content: str, author: str, timestamp: str) -> dict:
|
||||
message = {
|
||||
|
||||
@ -69,12 +69,9 @@ def api_mate_trinken(row, column):
|
||||
|
||||
@app.route('/api/chat/', methods=['GET'])
|
||||
def api_chat():
|
||||
if not Chat.initialized:
|
||||
Chat.init()
|
||||
messages = Chat.getAllMessages()
|
||||
print(messages)
|
||||
response = jsonify(success=True, messages=json_util.dumps(messages))
|
||||
response.status_code = 200
|
||||
messages = Chat.getNext100Messages(0) # 0 offset print(messages)
|
||||
response = jsonify(success=True, messages=json_util.dumps(messages))
|
||||
response.status_code = 200
|
||||
return response
|
||||
|
||||
@socketio.on('chat-message')
|
||||
@ -112,5 +109,6 @@ def page_not_found(error):
|
||||
return render_template('404.html'), response
|
||||
|
||||
if __name__ == '__main__':
|
||||
Chat.init()
|
||||
socketio.run(app, debug=True, host='localhost', port=5000) #pragma: no cover
|
||||
|
||||
|
||||
@ -425,6 +425,5 @@ margin-right: auto;
|
||||
|
||||
#chatBox {
|
||||
background-color: green;
|
||||
max-height: 200px;
|
||||
height: 70%;
|
||||
max-height: 600px;
|
||||
}
|
||||
|
||||
@ -8,6 +8,6 @@ Chat.init()
|
||||
def generate_message():
|
||||
Chat.insertMessage(fake.text(), fake.name(), fake.date_time().isoformat())
|
||||
|
||||
MESSAGE_COUNT = 1000
|
||||
MESSAGE_COUNT = 100000
|
||||
for i in range(MESSAGE_COUNT):
|
||||
generate_message()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user