Browse SDKs · React Native
Platform
SDKsReact Native

Get friend list by page

Paginate and retrieve the friend list with filtering options using the OpenIM React Native SDK.

Copy

Paginate and retrieve the friend list of the authenticated user with optional blacklist filtering:

const friends = await OpenIMSDK.getFriendListPage({
  offset: 0,
  count: 50,
  filterBlack: true,
});

Parameters

ParameterTypeRequiredDescription
offsetnumberYesPagination offset starting from 0.
countnumberYesMaximum number of friends to retrieve per batch.
filterBlackbooleanNoWhether to exclude blacklisted users; defaults to false.

Return value

Resolves to an array of FriendUserItem[] for the requested page.

Friend properties

Key properties of FriendUserItem:

FieldTypeDescription
userIDstringUnique friend user ID and primary state reconciliation key.
nicknamestringFriend account nickname.
faceURLstringFriend avatar image URL.
remarkstringCustom remark alias set for this friend by the current user.
isPinnedbooleanWhether this friend is pinned in the friend list.
ownerUserIDstringUser ID who owns this friendship relation.
operatorUserIDstringUser ID of the operator who last modified the relationship.
addSourcenumberSource channel through which the friendship was established.
createTimenumberFriendship establishment timestamp in Unix milliseconds.
exstringRelationship-specific custom extension string.
attachedInfostringSDK internal metadata.

Note that remark, isPinned, and ex are scoped strictly to the current user's friendship record and do not alter the friend's global profile.

Listen for friend updates

Friendship updates trigger OnFriendAdded, OnFriendInfoChanged, or OnFriendDeleted with the affected FriendUserItem:

const handleFriendAdd = (friend: FriendUserItem) => {
  // Insert new friend into list
};

const handleFriendChanged = (friend: FriendUserItem) => {
  // Update friend attributes matching friend.userID
};

const handleFriendDeleted = (friend: FriendUserItem) => {
  // Remove friend matching friend.userID from list
};

// Register listeners
OpenIMSDK.on(OpenIMEvent.OnFriendAdded, handleFriendAdd);
OpenIMSDK.on(OpenIMEvent.OnFriendInfoChanged, handleFriendChanged);
OpenIMSDK.on(OpenIMEvent.OnFriendDeleted, handleFriendDeleted);

// Remove listeners
OpenIMSDK.off(OpenIMEvent.OnFriendAdded, handleFriendAdd);
OpenIMSDK.off(OpenIMEvent.OnFriendInfoChanged, handleFriendChanged);
OpenIMSDK.off(OpenIMEvent.OnFriendDeleted, handleFriendDeleted);

Unregister these listeners when the friend list screen unmounts, the user signs out, or accounts switch.