Browse SDKs · uni-app / uni-app x
SDKsuni-appEnterprise

Load message context

OpenIM uni-app / uni-app x SDK guide for Load message context.

Copy

When navigating from a search result or quoted message into chat context, use the complete OpenIMMessageItem you already obtained as the anchor. fetchSurroundingMessages() is Commercial.

Parameters

ParameterTypeRequiredDescription
startMessageOpenIMMessageItemYesComplete anchor message.
viewTypenumberYesContext direction defined by the server contract.
beforenumberYesMaximum number of messages before the anchor.
afternumberYesMaximum number of messages after the anchor.
import { fetchSurroundingMessages } from '@/uni_modules/unix-openim-sdk'

const result = await fetchSurroundingMessages({
  startMessage: targetMessage,
  viewType: 0,
  before: 20,
  after: 20,
})
const surroundingMessages = result?.messages ?? []

On success, result?.messages is the surrounding OpenIMMessageItem[]. The uni-app / uni-app x field is messages, not the Wasm messageList field.

before and after limit each side of the anchor. The result can contain fewer messages near a boundary or after deletions. It can also overlap realtime events, so deduplicate by conversationID:clientMsgID and preserve chronological order. Do not construct a fake anchor containing only an ID; first use Find messages by ID when necessary.