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

Get the conversation list

OpenIM uni-app / uni-app x SDK guide for Get the conversation list.

Copy

Build the conversation-list snapshot with paginated getConversationListSplit(). Although the Private contract still exports getAllConversationList() for compatibility, real applications and public documentation use the paginated operation so a large local database is not loaded in one call.

Get conversations by page

Parameters

ParameterTypeRequiredDescription
offsetnumberYesPagination offset; use 0 for the first page.
countnumberYesNumber to read. Choose a reasonable limit for the page and device.
import {
  getConversationListSplit,
  off,
  onConversationChanged,
  onNewConversation,
} from '@/uni_modules/unix-openim-sdk'

const newConversationSubscription = onNewConversation((result) => {
  result.conversations.forEach((item) => {
    upsertConversation(item.conversationID, item)
  })
})
const changedSubscription = onConversationChanged((result) => {
  result.conversations.forEach((item) => {
    upsertConversation(item.conversationID, item)
  })
})

const firstPage = await getConversationListSplit({ offset: 0, count: 100 })
replaceConversationSnapshot(firstPage?.conversations ?? [])

The Promise resolves directly to OpenIMConversationListResult or null; read the page from conversations. Replace the current account snapshot with the first page and merge later pages by conversationID. Do not fabricate a successful empty list for null; use login state and redacted diagnostics to decide whether to preserve the old snapshot or show a loading error.

Increase offset until a page contains fewer than count items. Conversation events received during paging can change sorting and page boundaries. Merge by primary key, then rebuild from offset 0 on refresh or synchronization completion. Do not permanently append pages while relying on stale offsets.

Conversation fields

Common OpenIMConversationItem fields include:

FieldDescription
conversationIDStable key for list snapshots and events.
conversationTypeOne-to-one, group, or notification conversation type.
userID / groupIDPeer user or target group according to the conversation type.
showName / faceURLDisplay-name and avatar snapshots.
unreadCountCurrent unread count.
latestMsgSerialized latest message. Preserve the conversation and show a fallback summary if parsing fails.
latestMsgSendTimeSend time of the latest message; can participate in normal ordering.
draftText / draftTextTimeLocal draft and its update time.
isPinnedPin state. Apply pin ordering before time ordering.
recvMsgOptConversation-level message reception option.

See Conversation overview for complete fields and commercial extensions. Never update by array index because pin state, latest message, draft, and unread count can all reorder the list.

Sort the list

Write page and event results into a map keyed by conversationID, then derive the visible array. A common policy puts pinned conversations first, orders each section by latest message or draft time, and uses a stable ID tiebreaker. Do not swap page-array items directly inside event handlers.

If latestMsg cannot be parsed, keep the conversation and show an unknown-message summary. A later recognizable message or requery will update it naturally.

Keep the list synchronized

This page is the complete owner for onNewConversation and onConversationChanged. Register events before the first query to minimize gaps during login synchronization. Both callbacks contain OpenIMConversationListResult; iterate every item even if one conversation usually changed.

Promise success, event arrival, and requery are separate stages. Rebuild the snapshot after foreground restoration, synchronization completion, reconnect, or account switch. On logout or store destruction, release the two owned handles:

off(newConversationSubscription)
off(changedSubscription)

When switching accounts, stop writes from old-account paging requests before querying the new account. A late old Promise must not merge its conversationID list into the new account. Use an application account generation or the commercial sdkSessionEpoch to revalidate before completion.