Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Load older messages

Paginate backward to retrieve older historical messages in a conversation.

Copy

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

ParameterTypeRequiredDescription
conversationIDstringYesIdentifier of the conversation whose history is being queried.
startClientMsgIDstringYesAnchor message ID; pass an empty string "" for the first page.
countnumberYesMaximum 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:

FieldTypeDescription
messageListOpenIMMessageItem[]Messages retrieved for this page.
isEndbooleanIndicates whether the earliest boundary of conversation history has been reached.
errCodenumberResult status code; 0 indicates successful retrieval.
errMsgstringDiagnostic 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.