Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Load newer messages

Paginate forward chronologically towards newer messages from an anchor message.

Copy

When navigating into a chat from search results or replied quotes and needing to fetch records newer than the anchor, set isReverse: true. This is a historical fetch method, not a real-time message listener.

Code example

import sdk, {
  ErrorCode,
  GetHistoryMessageListReq,
  GetHistoryMessageListResp,
  ViewType,
} from '@openimsdk/imsdk';

const request: GetHistoryMessageListReq = {
  conversationID: conversationID,
  startClientMsgID: anchorMessage.clientMsgID,
  count: 30,
  isReverse: true,
  viewType: ViewType.ViewHistory,
};
const response: GetHistoryMessageListResp = await sdk.getHistoryMessageList(request);
if (response.errCode === ErrorCode.NoError) {
  appendMessages(response.messageList);
}

Parameters

ParameterTypeRequiredDescription
conversationIDstringYesTarget conversation identifier.
startClientMsgIDstringYesClient message ID of the anchor message.
countnumberYesNumber of messages to retrieve.
isReversebooleanYesPass true for reverse pagination towards newer messages.
viewTypeViewTypeYesMessage view mode, typically ViewType.ViewHistory.

Return value

Returns a Promise resolving to GetHistoryMessageListResp:

PropertyTypeDescription
errCodeErrorCodeSDK error code enum value (ErrorCode.NoError indicates success).
errMsgstringError description if errCode is non-zero.
messageListIMMessage[]Array of newer messages retrieved.
isEndbooleantrue if no newer historical messages exist.

State changes after the call

The anchor message must have a valid clientMsgID. When continuing pagination, advance the anchor to the latest received message; isEnd signals whether the newest boundary of synchronized history has been reached. Avoid alternating directions simultaneously on the same viewport boundary, and deduplicate by stable ID when appending to timeline feeds.