Browse SDKs · React Native
Platform
SDKsReact NativeEnterprise

Load message context

Retrieve contextual messages before and after an anchor message using the OpenIM React Native SDK.

Copy

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

ParameterTypeRequiredDescription
startMessageMessageItemYesReference anchor message object.
viewTypeViewTypeYesContext navigation mode; pass ViewType.Search when navigating from search results.
beforenumberYesMaximum number of earlier messages to load before the anchor.
afternumberYesMaximum 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 + 1 if 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.