SDKsWASMEnterprise
Load message context
Retrieve messages before and after a specified message with the WASM SDK.
When navigating from a search result or referenced message into its chat context, use the MessageItem you have already retrieved as the anchor.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
startMessage | MessageItem | Yes | Previously retrieved anchor message. |
viewType | ViewType | Yes | Context viewing direction. Use ViewType.History for message history. |
before | number | Yes | Maximum number of messages to retrieve before the anchor. |
after | number | Yes | Maximum number of messages to retrieve after the anchor. |
import { ViewType } from '@openim/wasm-client-sdk';
const { data: surrounding } = await openimsdk.fetchSurroundingMessages({
startMessage: targetMessage,
viewType: ViewType.History,
before: 20,
after: 20,
});
renderMessages(surrounding.messageList);When the Promise resolves, data.messageList is the MessageItem[] retrieved before and after the anchor. For message fields, see Message overview.
before and after independently limit the number of messages on either side. The result can contain fewer messages than the requested total when the anchor is near a history boundary or some messages have been deleted. Merge by conversationID:clientMsgID; do not rely on fixed array positions. If you first need to locate the message, see Find messages by ID.
Was this page helpful?