Browse SDKs · WASM
SDKsWASM

Get received friend applications

Page through friend applications received by the current user.

Copy

Call getFriendApplicationListAsRecipient() with handleResults, offset, and count to page through applications received by the current user.

Parameters

ParameterTypeRequiredDescription
handleResultsnumber[]YesApplication results to query. Pass an empty array to include every processing result.
offsetnumberYesPagination offset. Pass 0 for the first page.
countnumberYesNumber of applications to request.
Enum valueNumeric valueMeaning
ApplicationHandleResult.Unprocessed0Pending.
ApplicationHandleResult.Accepted1Accepted.
ApplicationHandleResult.Rejected-1Rejected.
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

FieldTypeDescription
fromUserIDstringUser ID of the applicant.
fromNicknamestringApplicant nickname stored with the application record.
fromFaceURLstringApplicant avatar stored with the application record.
toUserIDstringUser ID of the recipient.
toNicknamestringRecipient nickname stored with the application record.
toFaceURLstringRecipient avatar stored with the application record.
reqMsgstringMessage included with the application.
handleResultApplicationHandleResultCurrent result: pending, accepted, or rejected.
handlerUserIDstringUser ID that processed the application. It can be empty while pending.
handleMsgstringExplanation entered while processing the application.
handleTimenumberProcessing time as a Unix timestamp in milliseconds. Do not treat it as valid while the application is pending.
createTimenumberTime when the application record was created, as a Unix timestamp in milliseconds.
exstringExtension string for the application record.
attachedInfostring (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.