SDKsReact NativeEnterprise
Load message context
Retrieve contextual messages before and after an anchor message using the OpenIM React Native SDK.
Retrieve adjacent surrounding messages preceding and following a known anchor message:
Use this method when a user navigates to a specific message from search results, quoted replies, or deep links to reconstruct the complete conversational context.
const { messageList } = await OpenIMSDK.fetchSurroundingMessages({
startMessage: targetMessage,
viewType: ViewType.Search,
before: 20,
after: 20,
});Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
startMessage | MessageItem | Yes | Reference anchor message object. |
viewType | ViewType | Yes | Context navigation mode; pass ViewType.Search when navigating from search results. |
before | number | Yes | Maximum number of earlier messages to load before the anchor. |
after | number | Yes | Maximum number of newer messages to load after the anchor. |
Return value
A resolved Promise returns an object containing { messageList: MessageItem[] }.
- Messages are sorted in ascending chronological order and include the anchor message itself.
- The returned count may be less than
before + after + 1if the anchor is close to conversation boundaries or adjacent messages have been deleted. - Deduplicate and merge retrieved records into the active conversation view using
clientMsgID.
Was this page helpful?