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. |
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.Agree | 1 | Accepted. |
ApplicationHandleResult.Reject | -1 | Rejected. |
import {
ApplicationHandleResult,
CbEvents,
} 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 | Snapshot of the applicant's nickname. |
fromFaceURL | string | Snapshot of the applicant's avatar. |
toUserID | string | User ID of the recipient. |
toNickname | string | Snapshot of the recipient's nickname. |
toFaceURL | string | Snapshot of the recipient's avatar. |
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. Do not treat it as valid while the application is pending. |
createTime | number | Time when the application record was created. |
ex | string | Extension string for the application record. |
Use fromUserID:toUserID as the merge key for application records. Nicknames and avatars are snapshots captured 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 owns the complete listeners for OnFriendApplicationAdded, OnFriendApplicationAccepted, OnFriendApplicationRejected, and OnFriendApplicationDeleted.
const handleApplicationChanged = ({ data }) =>
mergeFriendApplication(data);
const handleApplicationDeleted = ({ data }) =>
removeFriendApplication(data.fromUserID, data.toUserID);
openimsdk.on(
CbEvents.OnFriendApplicationAdded,
handleApplicationChanged,
);
openimsdk.on(
CbEvents.OnFriendApplicationAccepted,
handleApplicationChanged,
);
openimsdk.on(
CbEvents.OnFriendApplicationRejected,
handleApplicationChanged,
);
openimsdk.on(
CbEvents.OnFriendApplicationDeleted,
handleApplicationDeleted,
);
function removeFriendApplicationListeners() {
openimsdk.off(
CbEvents.OnFriendApplicationAdded,
handleApplicationChanged,
);
openimsdk.off(
CbEvents.OnFriendApplicationAccepted,
handleApplicationChanged,
);
openimsdk.off(
CbEvents.OnFriendApplicationRejected,
handleApplicationChanged,
);
openimsdk.off(
CbEvents.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, merge the new friendship through OnFriendAdded, which is owned by Get the friend list.
Was this page helpful?