From ecf74d91e25b00d3421195740577eafcc0aff703 Mon Sep 17 00:00:00 2001 From: Eric Guo Date: Thu, 28 Aug 2025 15:05:52 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8fix:=20has=5Fmore=20logic=20in=20ChatM?= =?UTF-8?q?essageListApi=20to=20ensure=20correct=20on=20behavior=20when=20?= =?UTF-8?q?no=20more=20messages=20are=20available.=20(#24661)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/console/app/message.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/api/controllers/console/app/message.py b/api/controllers/console/app/message.py index 05b668b803..fd86191a07 100644 --- a/api/controllers/console/app/message.py +++ b/api/controllers/console/app/message.py @@ -95,18 +95,22 @@ class ChatMessageListApi(Resource): .all() ) + # Initialize has_more based on whether we have a full page if len(history_messages) == args["limit"]: current_page_first_message = history_messages[-1] - - has_more = db.session.scalar( - select( - exists().where( - Message.conversation_id == conversation.id, - Message.created_at < current_page_first_message.created_at, - Message.id != current_page_first_message.id, + # Check if there are more messages before the current page + has_more = db.session.scalar( + select( + exists().where( + Message.conversation_id == conversation.id, + Message.created_at < current_page_first_message.created_at, + Message.id != current_page_first_message.id, + ) ) ) - ) + else: + # If we don't have a full page, there are no more messages + has_more = False history_messages = list(reversed(history_messages))