diff --git a/chat.py b/chat.py index fa2511b1401dbb9eeab47547557b9f84039fa10a..d88e5a0ea664116d3b77383f4f234b49d5564fcc 100644 --- a/chat.py +++ b/chat.py @@ -43,12 +43,25 @@ async def echo(websocket): event = json.loads(message) #根据api-token查找房间号 room_id = name[websocket]['room_id'] + #历史记录数量 + if "history_num" in event["type"]: + if room_id in history : + # h = history[room_id][start*end - end:start*end] + h = len(history[room_id]) + else : + # h = [] + h = 0; + r = {'type':'history_num','content':h} + message = json.dumps(r,ensure_ascii=False) + await websocket.send(message) #历史记录 if "history" in event["type"]: start = int(event['page']) end = int(event['page_num']) + num = int(event['num']) if room_id in history : - h = history[room_id][start*end - end:start*end] + n = history[room_id][:num] + h = n[start*end - end:start*end] else : h = [] r = {'type':'history','content':h}