瀏覽代碼

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

tags/1.8.1
Eric Guo 2 月之前
父節點
當前提交
ecf74d91e2
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 12 行新增8 行删除
  1. 12
    8
      api/controllers/console/app/message.py

+ 12
- 8
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))


Loading…
取消
儲存