forked from Kelder/cammiechat
Merge branch 'swamp' into 'master'
Add API to get recent chat messages See merge request kelder/cammiechat!5
This commit is contained in:
commit
0e8ec152f0
1 changed files with 11 additions and 0 deletions
11
chat.py
11
chat.py
|
@ -141,5 +141,16 @@ def messages_post():
|
||||||
return "OK"
|
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__":
|
if __name__ == "__main__":
|
||||||
socketio.run(app)
|
socketio.run(app)
|
||||||
|
|
Loading…
Reference in a new issue