SDKsReact Native
Get friend list by page
Paginate and retrieve the friend list with filtering options using the OpenIM React Native SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
offset | number | Yes | Pagination offset starting from 0. |
count | number | Yes | Maximum number of friends to retrieve per batch. |
filterBlack | boolean | No | Whether 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:
| Field | Type | Description |
|---|---|---|
userID | string | Unique friend user ID and primary state reconciliation key. |
nickname | string | Friend account nickname. |
faceURL | string | Friend avatar image URL. |
remark | string | Custom remark alias set for this friend by the current user. |
isPinned | boolean | Whether this friend is pinned in the friend list. |
ownerUserID | string | User ID who owns this friendship relation. |
operatorUserID | string | User ID of the operator who last modified the relationship. |
addSource | number | Source channel through which the friendship was established. |
createTime | number | Friendship establishment timestamp in Unix milliseconds. |
ex | string | Relationship-specific custom extension string. |
attachedInfo | string | SDK 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.
Was this page helpful?