Open a conversation
Query a single conversation record by single-chat user ID or group ID.
When transitioning into a chat interface from a contact profile, user detail view, or group info card, query the conversation directly using its concrete target identifier. Supply the peer userID as sourceID for single chats, or the groupID as sourceID for group chats. Always use the SDK query method rather than attempting to concatenate conversationID strings or manually construct conversation objects.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
sourceID | string | Yes | Target identifier: peer user ID for single chats, or group ID for group chats. |
sessionType | OpenIMSessionType | Yes | Use OpenIMSessionTypeSingle for single chats, or OpenIMSessionTypeWriteGroup for standard group chats. |
Code example
import {
OpenIMSessionTypeSingle,
getOneConversation,
} from '@/uni_modules/unix-openim-sdk'
const conversation = await getOneConversation({
sourceID: targetUserID,
sessionType: OpenIMSessionTypeSingle,
})
if (conversation != null) {
openChatPage(conversation)
}Return value
The Promise resolves with an OpenIMConversationItem | null object. For a detailed breakdown of returned conversation fields, see Retrieve conversation list.
State changes after the call
This query returns the local snapshot at the moment of invocation and does not trigger conversation events. Merge subsequent incremental updates using conversationID as the primary key. For complete event subscription and state merging patterns, see Retrieve conversation list.
Was this page helpful?