Get the friend list
Page through the current user’s friend list.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
offset | number | Yes | Pagination offset. Pass 0 for the first page. |
count | number | Yes | Number of friends to request. |
filterBlack | boolean | No | Whether to exclude blacklisted users from the results. |
const { data: friends } = await openimsdk.getFriendListPage({
offset: 0,
count: 50,
filterBlack: true,
});After the Promise succeeds, data contains the current page of FriendUserItem[]. Increase offset by the requested item count to load the next page. Reset pagination after a friend is added or removed.
Friend profile fields
FriendUserItem describes the current account's relationship with one friend:
| Field | Type | Description |
|---|---|---|
userID | string | The friend's user ID, used to find the matching friend when an event arrives. |
nickname | string | The friend's account-level nickname. |
faceURL | string | The friend's account-level avatar URL. |
remark | string | A remark the current account assigned to this friend. |
isPinned | boolean | Whether the friend is pinned in the contacts list. |
ownerUserID | string | The user ID that owns this friendship, normally the current account. |
operatorUserID | string | The user ID that created or updated the relationship. |
addSource | number | Value describing the source through which the friendship was added. |
createTime | number | Time when the friendship was created, as a Unix timestamp in milliseconds. |
ex | string | Friendship extension string. |
attachedInfo | string | SDK attachment data. Parse it only according to a confirmed application contract. |
nickname and faceURL contain the account nickname and avatar returned by this query. remark, isPinned, ex, and attachedInfo belong to the friendship. Do not overwrite a non-friend's PublicUserItem with a FriendUserItem, and do not write a friend remark back to the account nickname.
Synchronize friend changes
This page provides the complete listeners for OnFriendAdded, OnFriendInfoChanged, and OnFriendDeleted. Use the query result to display the friend list when the page first opens. For later events, use userID to find and update or remove the matching friend.
import { SdkEvent } from '@openim/wasm-client-sdk';
const handleFriendChanged = ({ data }) => mergeFriend(data);
const handleFriendDeleted = ({ data }) => removeFriend(data.userID);
openimsdk.on(SdkEvent.OnFriendAdded, handleFriendChanged);
openimsdk.on(SdkEvent.OnFriendInfoChanged, handleFriendChanged);
openimsdk.on(SdkEvent.OnFriendDeleted, handleFriendDeleted);
function removeFriendListeners() {
openimsdk.off(SdkEvent.OnFriendAdded, handleFriendChanged);
openimsdk.off(SdkEvent.OnFriendInfoChanged, handleFriendChanged);
openimsdk.off(SdkEvent.OnFriendDeleted, handleFriendDeleted);
}Call removeFriendListeners() when signing out, switching accounts, or destroying the contacts state layer.
Was this page helpful?