✨fix: has_more logic in ChatMessageListApi to ensure correct on behavior when no more messages are available. (#24661)

This commit is contained in:
Eric Guo 2025-08-28 15:05:52 +08:00 • committed by GitHub
commit ecf74d91e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -95,9 +95,10 @@ class ChatMessageListApi(Resource):
.all() .all()
) )
# Initialize has_more based on whether we have a full page
if len(history_messages) == args["limit"]: if len(history_messages) == args["limit"]:
current_page_first_message = history_messages[-1] current_page_first_message = history_messages[-1]
# Check if there are more messages before the current page
has_more = db.session.scalar( has_more = db.session.scalar(
select( select(
exists().where( exists().where(
@ -107,6 +108,9 @@ class ChatMessageListApi(Resource):
) )
) )
) )
else:
# If we don't have a full page, there are no more messages
has_more = False
history_messages = list(reversed(history_messages)) history_messages = list(reversed(history_messages))