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

Open a conversation

OpenIM uni-app / uni-app x SDK guide for Open a conversation.

Copy

getOneConversation() queries one conversation by target ID and OpenIMSessionType. It resolves directly to OpenIMConversationItem or null.

Parameters

ParameterTypeRequiredDescription
sourceIDstringYesTarget ID: the other user's userID for one-to-one chat or groupID for group chat.
sessionTypeOpenIMSessionTypeYesConversation type. Use exported constants such as OpenIMSessionTypeSingle and the corresponding group type.
import {
  OpenIMSessionTypeSingle,
  getOneConversation,
} from '@/uni_modules/unix-openim-sdk'

const conversation = await getOneConversation({
  sourceID: 'user_b',
  sessionType: OpenIMSessionTypeSingle,
})

The same string can identify different targets under different session types, so both fields must be correct. Do not pass numeric literals, and do not pass a conversationID as sourceID; use the conversation-ID query when that ID is already known.

null can mean that the local database does not yet contain the conversation. Sending or receiving the first message can create it through a later event. This query does not create a conversation or trigger an event. Merge a non-null result by conversationID, not only by sourceID, so another session type is not overwritten.