SDKsReact NativeIncludes Enterprise features
Get received friend applications
Paginate and retrieve incoming friend requests by status using the OpenIM React Native SDK.
Paginate and query friend applications received by the authenticated user filtered by handling status:
const applications = await OpenIMSDK.getFriendApplicationListAsRecipient({
handleResults: [ApplicationHandleResult.Unprocessed],
offset: 0,
count: 20,
});Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
handleResults | number[] | Yes | List of application statuses to filter by. |
offset | number | Yes | Pagination offset starting from 0. |
count | number | Yes | Maximum number of records to fetch per batch. |
Status enum values:
| Enum value | Value | Description |
|---|---|---|
ApplicationHandleResult.Unprocessed | 0 | Pending review. |
ApplicationHandleResult.Agree | 1 | Approved. |
ApplicationHandleResult.Reject | -1 | Rejected. |
Return value
Resolves to an array of FriendApplicationItem[] for the requested page.
Friend application properties
Key properties in FriendApplicationItem:
| Field | Type | Description |
|---|---|---|
fromUserID | string | User ID of the applicant. |
fromNickname | string | Nickname of the applicant. |
fromFaceURL | string | Avatar URL of the applicant. |
toUserID | string | User ID of the recipient (the current user). |
toNickname | string | Nickname of the recipient. |
toFaceURL | string | Avatar URL of the recipient. |
reqMsg | string | Greeting message attached to the request. |
handleResult | ApplicationHandleResult | Current handling status. |
handlerUserID | string | User ID who processed the application. |
handleMsg | string | Response note provided when processing. |
handleTime | number | Processing timestamp in Unix milliseconds. |
createTime | number | Request creation timestamp in Unix milliseconds. |
ex | string | Custom extension string. |
Listen for friend application changes
Friend application events trigger OnFriendApplicationAdded, OnFriendApplicationAccepted, OnFriendApplicationRejected, or OnFriendApplicationDeletedEnterprise, delivering the affected FriendApplicationItem:
const handleApplicationChanged = (application: FriendApplicationItem) => {
// Update state using composite key fromUserID and toUserID
};
const handleApplicationDeleted = (application: FriendApplicationItem) => {
// Remove application matching fromUserID and toUserID
};
// Register listeners
OpenIMSDK.on(OpenIMEvent.OnFriendApplicationAdded, handleApplicationChanged);
OpenIMSDK.on(OpenIMEvent.OnFriendApplicationAccepted, handleApplicationChanged);
OpenIMSDK.on(OpenIMEvent.OnFriendApplicationRejected, handleApplicationChanged);
OpenIMSDK.on(OpenIMEvent.OnFriendApplicationDeleted, handleApplicationDeleted);
// Remove listeners
OpenIMSDK.off(OpenIMEvent.OnFriendApplicationAdded, handleApplicationChanged);
OpenIMSDK.off(OpenIMEvent.OnFriendApplicationAccepted, handleApplicationChanged);
OpenIMSDK.off(OpenIMEvent.OnFriendApplicationRejected, handleApplicationChanged);
OpenIMSDK.off(OpenIMEvent.OnFriendApplicationDeleted, handleApplicationDeleted);Identify individual application entries using the composite key fromUserID:toUserID. Unregister listeners when the view unmounts, the user signs out, or accounts switch.
Was this page helpful?