Get a conversation by target
Query detailed information for a single conversation using a target user ID or group ID.
Retrieve a snapshot of a single conversation using the target user ID or group ID. This is typically used when opening a chat screen directly from a contact card, group profile, or search result. If the conversation does not exist locally yet, the SDK creates and returns a base conversation entity automatically.
Code example
OpenIMClient.getInstance().conversationManager.getOneConversation(
new OnBase<ConversationInfo>() {
@Override
public void onSuccess(ConversationInfo conversation) {
// conversation contains the target conversation data.
}
@Override
public void onError(int code, String error) {
// code and error describe the failure.
}
},
sourceId,
ConversationType.SINGLE_CHAT
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
base | OnBase<ConversationInfo> | Yes | Callback delivering the asynchronous query result. |
sourceId | String | Yes | Target identifier. Pass the peer userID for direct chats or the groupID for group chats. |
sessionType | int | Yes | Conversation type: ConversationType.SINGLE_CHAT for direct chats; ConversationType.GROUP_CHAT or ConversationType.SUPER_GROUP_CHAT for group chats. |
Return value
The successful callback returns the ConversationInfo snapshot of the target conversation, containing unread counts, draft text, pinning status, and the latest message. Use conversation.conversationID as the unique key to merge or cache conversation state.
To monitor conversation property modifications or incoming messages continuously, register OnConversationListener at the application layer as shown in Get the conversation list.
Was this page helpful?