Add API to get recent chat messages
This commit is contained in:
parent
2efcdb0624
commit
95dcdea1c1
1 changed files with 11 additions and 0 deletions
11
chat.py
11
chat.py
|
@ -136,5 +136,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)
|
||||
|
|
Loading…
Reference in a new issue