SDKsHarmonyOSEnterprise
Load older messages
Paginate backward chronologically to retrieve older message history in a conversation.
Pass an empty string "" for startClientMsgID when fetching the initial page; for subsequent backward pages, pass the client message ID of the oldest currently rendered message.
Code example
import sdk, {
ErrorCode,
GetHistoryMessageListReq,
GetHistoryMessageListResp,
ViewType,
} from '@openimsdk/imsdk';
const request: GetHistoryMessageListReq = {
conversationID: conversationID,
startClientMsgID: oldestClientMsgID,
count: 30,
isReverse: false,
viewType: ViewType.ViewHistory,
};
const response: GetHistoryMessageListResp = await sdk.getHistoryMessageList(request);
if (response.errCode === ErrorCode.NoError) {
prependMessages(response.messageList);
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | Target conversation identifier. |
startClientMsgID | string | Yes | Client message ID of the oldest message, or "" for the first page. |
count | number | Yes | Number of messages to retrieve per page. |
isReverse | boolean | Yes | Pass false for backwards chronological paging. |
viewType | ViewType | Yes | Message view mode, typically ViewType.ViewHistory. |
Return value
Returns a Promise resolving to GetHistoryMessageListResp:
| Property | Type | Description |
|---|---|---|
errCode | ErrorCode | SDK error code enum value (ErrorCode.NoError indicates success). |
errMsg | string | Error description if errCode is non-zero. |
messageList | IMMessage[] | Array of older messages retrieved. |
isEnd | boolean | true if the oldest message in history has been reached. |
State changes after the call
Cease paging backward when isEnd becomes true. Treat rejected Promises and responses with non-zero errCode as load failures. This query does not trigger new message events; when prepending results, scope mutations to the current conversationID and deduplicate by clientMsgID.
Was this page helpful?