Merge branch 'swamp' into 'master'

Add API to get recent chat messages

See merge request kelder/cammiechat!5
This commit is contained in:
j 2022-02-28 18:58:51 +00:00
commit 0e8ec152f0

11
chat.py
View file

@ -141,5 +141,16 @@ def messages_post():
return "OK"
# make sure only messages from the last hour are sent
# this command also only sends messages the user doesn't have yet.
@app.route('/<last_index>/api.json')
def api(last_index):
curr_time = datetime.now()
ci = len(messages)-1
while curr_time - messages[ci].time < datetime.timedelta(hours = 1) and ci > last_index:
ci -= 1
return jsonify({"newest_msg_index": len(messages) , "messages": messages[ci:]})
if __name__ == "__main__":
socketio.run(app)