account for different chats sharing message ids

master
Aevann 2024-11-12 22:48:27 +02:00
parent c986bd71a8
commit 61b52ce2d9
1 changed files with 5 additions and 4 deletions

View File

@ -92,11 +92,12 @@ def chat(v, chat_id):
message_id = request.values.get('m') message_id = request.values.get('m')
if message_id: if message_id:
message_id = int(message_id) message_id = int(message_id)
start = message_id - 125 part_1 = list(reversed(displayed_messages.filter(ChatMessage.id <= message_id).order_by(ChatMessage.id.desc()).limit(125).all()))
finish = message_id + 125 part_2 = displayed_messages.filter(ChatMessage.id > message_id).order_by(ChatMessage.id).limit(125).all()
displayed_messages = displayed_messages.filter(ChatMessage.id > start, ChatMessage.id < finish) displayed_messages = part_1 + part_2
else:
displayed_messages = reversed(displayed_messages.order_by(ChatMessage.id.desc()).limit(250).all())
displayed_messages = reversed(displayed_messages.order_by(ChatMessage.id.desc()).limit(250).all())
displayed_messages = {m.id: m for m in displayed_messages} displayed_messages = {m.id: m for m in displayed_messages}
if chat.id == 1: if chat.id == 1: