From f636970a393a63c6be8c853fc26f83985d042377 Mon Sep 17 00:00:00 2001 From: gaojiangxia <1551959560@qq.com> Date: Tue, 21 Nov 2023 13:51:07 +0800 Subject: [PATCH] a --- chat.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/chat.py b/chat.py index fa2511b..d88e5a0 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} -- Gitee