Get received friend applications
Page through friend applications received by the current user.
Call getFriendApplicationListAsRecipient() with handleResults, offset, and count to page through applications received by the current user.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
handleResults | number[] | Yes | Application results to query. Pass an empty array to include every processing result. |
offset | number | Yes | Pagination offset. Pass 0 for the first page. |
count | number | Yes | Number of applications to request. |
| Enum value | Numeric value | Meaning |
|---|---|---|
ApplicationHandleResult.Unprocessed | 0 | Pending. |
ApplicationHandleResult.Accepted | 1 | Accepted. |
ApplicationHandleResult.Rejected | -1 | Rejected. |
import {
ApplicationHandleResult,
SdkEvent,
} from '@openim/wasm-client-sdk';
const { data: applications } =
await openimsdk.getFriendApplicationListAsRecipient({
handleResults: [ApplicationHandleResult.Unprocessed],
offset: 0,
count: 20,
});After the Promise succeeds, data contains the current page of FriendApplicationItem[]. The query does not trigger an application event.
Friend application fields
| Field | Type | Description |
|---|---|---|
fromUserID | string | User ID of the applicant. |
fromNickname | string | Applicant nickname stored with the application record. |
fromFaceURL | string | Applicant avatar stored with the application record. |
toUserID | string | User ID of the recipient. |
toNickname | string | Recipient nickname stored with the application record. |
toFaceURL | string | Recipient avatar stored with the application record. |
reqMsg | string | Message included with the application. |
handleResult | ApplicationHandleResult | Current result: pending, accepted, or rejected. |
handlerUserID | string | User ID that processed the application. It can be empty while pending. |
handleMsg | string | Explanation entered while processing the application. |
handleTime | number | Processing time as a Unix timestamp in milliseconds. Do not treat it as valid while the application is pending. |
createTime | number | Time when the application record was created, as a Unix timestamp in milliseconds. |
ex | string | Extension string for the application record. |
attachedInfo | string (optional) | SDK attachment data. Parse it only according to a confirmed application contract. |
Use fromUserID:toUserID to identify a friend application. The nicknames and avatars are the profile data stored when the application was created or synchronized. Query the latest account profile by userID when required.
Synchronize friend application changes
Locate a friend application by fromUserID:toUserID. This page provides the complete listeners for OnFriendApplicationAdded, OnFriendApplicationAccepted, OnFriendApplicationRejected, and OnFriendApplicationDeleted.
const handleApplicationChanged = ({ data }) =>
mergeFriendApplication(data);
const handleApplicationDeleted = ({ data }) =>
removeFriendApplication(data.fromUserID, data.toUserID);
openimsdk.on(
SdkEvent.OnFriendApplicationAdded,
handleApplicationChanged,
);
openimsdk.on(
SdkEvent.OnFriendApplicationAccepted,
handleApplicationChanged,
);
openimsdk.on(
SdkEvent.OnFriendApplicationRejected,
handleApplicationChanged,
);
openimsdk.on(
SdkEvent.OnFriendApplicationDeleted,
handleApplicationDeleted,
);
function removeFriendApplicationListeners() {
openimsdk.off(
SdkEvent.OnFriendApplicationAdded,
handleApplicationChanged,
);
openimsdk.off(
SdkEvent.OnFriendApplicationAccepted,
handleApplicationChanged,
);
openimsdk.off(
SdkEvent.OnFriendApplicationRejected,
handleApplicationChanged,
);
openimsdk.off(
SdkEvent.OnFriendApplicationDeleted,
handleApplicationDeleted,
);
}Route each event to the received or sent list according to whether the current user is toUserID. Reset pagination if a change arrives while paging. After an application is accepted, use the OnFriendAdded event described in Get the friend list to update the friend list.
Was this page helpful?