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

Retrieve conversation list

Query the authenticated user’s conversation list with pagination and listen for ongoing conversation updates.

Copy

The conversation list belongs to the currently authenticated account. Load conversation items using pagination to avoid memory and rendering bottlenecks associated with fetching the entire database at once. Begin the first page at offset: 0 and increment the offset by the cumulative number of items fetched so far.

Parameters

ParameterTypeRequiredDescription
offsetnumberYesStarting pagination offset; supply 0 for the first page.
countnumberYesMaximum number of conversations to retrieve in this page.

Code example

import { getConversationListSplit } from '@/uni_modules/unix-openim-sdk'

const result = await getConversationListSplit({
  offset: 0,
  count: 50,
})
const conversations = result?.conversations ?? []
mergeConversations(conversations)

Return value

The Promise resolves with an OpenIMConversationListResult | null object. The retrieved page items are stored in conversations (OpenIMConversationItem[]). Deduplicate and merge items into your application state using conversationID. When the returned array contains fewer items than count, the end of the cached conversation list has been reached. Upon re-login, account switching, or manual pull-to-refresh, clear local paginated state and query again starting from offset 0.

Conversation fields

The OpenIMConversationItem object consolidates target identification, list rendering metadata, and account-specific conversation configuration:

FieldTypeDescription
conversationIDstringStable unique conversation identifier; serves as the primary key for queries and event merging.
conversationTypeOpenIMSessionTypeSession type, such as single chat (OpenIMSessionTypeSingle) or group chat (OpenIMSessionTypeWriteGroup).
userIDstring | nullPeer user ID in a single chat; empty string or null in group chats.
groupIDstring | nullTarget group ID in a group chat; empty string or null in single chats.
showNamestringDisplay name of the conversation for UI rendering.
faceURLstringAvatar image URL of the conversation.
latestMsgstring | nullSerialized JSON string of the latest message, or null if no displayable message exists.
latestMsgSendTimenumberSend timestamp of the latest message in Unix milliseconds.
unreadCountnumberTotal unread message count for the authenticated account in this conversation.
recvMsgOptOpenIMMessageReceiveOptionMessage receive option, such as normal reception, muting, or suppressing notifications.
groupAtTypeOpenIMGroupMentionTypeGroup @ mention status; not applicable to single chats.
draftTextstringLocally saved message draft string.
draftTextTimenumberTimestamp when the draft was last updated, in Unix milliseconds.
isPinnedbooleanWhether the conversation is pinned to the top of the list.
isMarked Commercialboolean | nullWhether the authenticated user marked this conversation. Marked conversations are grouped into built-in tag views.
remark Commercialstring | nullCustom alias remark set for this conversation by the authenticated user; null if unset.
isPrivateChat CommercialbooleanWhether burn-after-reading private chat mode is enabled.
burnDuration CommercialnumberPrivate chat burn-after-reading countdown duration in seconds.
isMsgDestruct CommercialbooleanWhether periodic server-side message self-destruction is enabled.
msgDestructTime CommercialnumberServer-side message destruction interval in seconds.
isNotInGroupbooleanIndicates whether the current account is no longer a member of the group.
updateUnreadCountTimenumberTimestamp when the unread count was last updated, in Unix milliseconds.
minSeqnumberSmallest synchronized message sequence number in this conversation.
maxSeqnumberLargest synchronized message sequence number in this conversation.
exstringCustom extension string attached to the conversation record.
attachedInfostringSDK internal auxiliary string; parse only according to confirmed business protocols.

Render conversation titles and avatars with showName and faceURL. When contact or group details change, refresh them through profile event listeners or re-queries; never compute conversation IDs from display names.

State changes after the call

New conversations and incremental updates are synchronized via event subscriptions. Both events deliver an OpenIMConversationListResult | null payload containing one or more updated conversations; iterate over conversations and merge updates by conversationID.

import {
  OpenIMConversationListResult,
  off,
  onConversationChanged,
  onNewConversation,
} from '@/uni_modules/unix-openim-sdk'

const handleConversationUpdates = (
  result: OpenIMConversationListResult | null,
) => {
  if (result == null) return
  mergeConversations(result.conversations)
}

const newConversationSubscription = onNewConversation(
  handleConversationUpdates,
)
const conversationChangedSubscription = onConversationChanged(
  handleConversationUpdates,
)

function removeConversationListListeners() {
  off(newConversationSubscription)
  off(conversationChangedSubscription)
}

Invoke removeConversationListListeners() when the component unmounts, or when logging out or switching accounts. Do not substitute the joined group list for the conversation list: a user may belong to groups that have not yet generated a conversation item, and historical conversation entries may persist even after leaving a group.