Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Retrieve conversation by target

Look up an individual conversation record by target user ID or group ID.

Copy

When navigating into a chat interface from a user profile, contact card, or group information view, query the corresponding conversation record by its target entity:

Code example

import sdk, { GetOneConversationReq, GetOneConversationResp, SessionType } from '@openimsdk/imsdk';

const request: GetOneConversationReq = {
  sourceID: targetUserID,
  sessionType: SessionType.Single,
};
const response: GetOneConversationResp = await sdk.getOneConversation(request);
openChatPage(response.conversation);

Parameters

ParameterTypeRequiredDescription
sourceIDstringYesTarget entity identifier: the peer userID for direct chats, or groupID for group chats.
sessionTypeSessionTypeYesSessionType.Single for direct chats or SessionType.WriteGroup for group chats.

Return value

Returns a Promise that resolves to a GetOneConversationResp object:

PropertyTypeDescription
conversationIMConversationThe matched conversation record.

State changes after the call

Resolving the Promise yields the current snapshot of the target conversation without triggering events. Subsequent unread badge changes, drafts, and message summaries are delivered through the conversation events documented in Retrieve conversation list.