Load older messages
Paginate backward to retrieve older historical messages in a conversation.
When entering a chat view or scrolling upward toward older history, invoke getAdvancedHistoryMessageList() to load messages backward in time. Pass an empty string "" for startClientMsgID on the initial request, and pass the oldest message's clientMsgID for subsequent pages.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | Identifier of the conversation whose history is being queried. |
startClientMsgID | string | Yes | Anchor message ID; pass an empty string "" for the first page. |
count | number | Yes | Maximum number of messages to retrieve in this page. |
Code example
import {
getAdvancedHistoryMessageList,
} from '@/uni_modules/unix-openim-sdk'
const page = await getAdvancedHistoryMessageList({
conversationID: conversationID,
startClientMsgID: oldestClientMsgID,
count: 30,
})
if (page != null && page.errCode == 0) {
prependMessages(page.messageList)
}For the initial query, initialize oldestClientMsgID as an empty string "". When paginating further backward, supply the clientMsgID of the earliest message in the current list as the new startClientMsgID. When isEnd is true, stop requesting older messages.
Return value
The Promise resolves with an OpenIMAdvancedHistoryMessageListResult | null object:
| Field | Type | Description |
|---|---|---|
messageList | OpenIMMessageItem[] | Messages retrieved for this page. |
isEnd | boolean | Indicates whether the earliest boundary of conversation history has been reached. |
errCode | number | Result status code; 0 indicates successful retrieval. |
errMsg | string | Diagnostic description accompanying errCode. |
State changes after the call
Both Promise rejection and a non-zero errCode indicate a failed query. This call performs a read-only query and does not emit new message events. Prepend retrieved messages to your conversation store scoped strictly to the current conversationID, deduplicating items by clientMsgID.
Was this page helpful?