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

Get the friend list

Query the authenticated user’s friends and relationship profiles with pagination.

Copy

Invoke getFriendListPage() to retrieve a paginated snapshot of the authenticated user's friend list. Start with offset: 0 for the first page, and increment the offset by the number of received records for subsequent pages. Reset pagination and re-query after additions or deletions occur.

Parameters

ParameterTypeRequiredDescription
offsetnumberYesPagination offset index; pass 0 for the initial page.
countnumberYesNumber of friend records to retrieve in this page.

The UTS pagination parameters do not include filterBlack. Friends and blacklisted contacts are maintained as distinct data sets; determine whether a friend is blacklisted by matching their userID against the list returned by Get the blacklist.

Code example

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

const result = await getFriendListPage({
  offset: 0,
  count: 50,
})
const friends = result?.friends ?? []
replaceFriends(friends)

Return value

The Promise resolves with an OpenIMFriendListResult | null object containing an array of OpenIMFriendUserItem elements in friends:

PropertyTypeDescription
userIDstringThe friend's user ID; serves as the primary merge key for relationship updates.
nicknamestringThe friend's account-level display nickname.
faceURLstringThe friend's account-level avatar URL.
remarkstringCustom friend alias or remark set by the current account.
isPinnedbooleanWhether this friend is pinned in the contact list.
ownerUserIDstringThe user ID owning this friendship record (the active account).
operatorUserIDstringThe user ID that created or last updated this friendship.
addSourcenumberNumeric source code describing how this friendship was initiated.
createTimenumberTimestamp when the friendship was formed, in Unix milliseconds.
exstringCustom relationship extension string.
attachedInfostringSDK internal metadata.

The nickname and faceURL fields reflect account data, while remark, isPinned, and ex are specific to this friendship. Do not write remarks back into account nicknames, and do not overwrite public stranger profiles with friend records.

Monitor friend updates

Friendship lifecycle events are centrally managed here. Use queries to populate initial state, and stream incremental updates via events. Merge items into your local state using userID:

import {
  OpenIMFriendUserItem,
  off,
  onFriendAdded,
  onFriendDeleted,
  onFriendInfoChanged,
} from '@/uni_modules/unix-openim-sdk'

const handleFriendChanged = (friend: OpenIMFriendUserItem | null) => {
  if (friend == null) return
  mergeFriend(friend)
}

const handleFriendDeleted = (friend: OpenIMFriendUserItem | null) => {
  if (friend == null) return
  removeFriend(friend.userID)
}

const friendAddedSubscription = onFriendAdded(handleFriendChanged)
const friendChangedSubscription = onFriendInfoChanged(handleFriendChanged)
const friendDeletedSubscription = onFriendDeleted(handleFriendDeleted)

function removeFriendListeners() {
  off(friendAddedSubscription)
  off(friendChangedSubscription)
  off(friendDeletedSubscription)
}

Unsubscribe from these listeners when logging out, switching accounts, or tearing down the contact store. If event delivery might have been interrupted during connection loss, re-query the full list to restore accuracy.