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.
offsetnumberYesPagination offset. Pass 0 for the first page.
countnumberYesNumber of applications to request.
Enum valueNumeric valueMeaning
ApplicationHandleResult.Unprocessed0Pending.
ApplicationHandleResult.Agree1Accepted.
ApplicationHandleResult.Reject-1Rejected.
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

FieldTypeDescription
fromUserIDstringUser ID of the applicant.
fromNicknamestringSnapshot of the applicant's nickname.
fromFaceURLstringSnapshot of the applicant's avatar.
toUserIDstringUser ID of the recipient.
toNicknamestringSnapshot of the recipient's nickname.
toFaceURLstringSnapshot of the recipient's avatar.
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. Do not treat it as valid while the application is pending.
createTimenumberTime when the application record was created.
exstringExtension 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.