Browse SDKs · React Native
SDKsReact Native

Get received friend applications

Get received friend requests with the OpenIM React Native SDK.

Copy

Call getFriendApplicationListAsRecipient() to page through friend requests received by the current user.

const applications = await OpenIMSDK.getFriendApplicationListAsRecipient({
  handleResults: [ApplicationHandleResult.Unprocessed],
  offset: 0,
  count: 20,
});

Parameter description

ParameterTypeRequiredDescription
handleResultsnumber[]YesRequest handling results to retrieve.
offsetnumberYesPagination offset. Use 0 for the first page.
countnumberYesNumber of requests to retrieve.
Enum valueNumeric valueMeaning
ApplicationHandleResult.Unprocessed0Pending.
ApplicationHandleResult.Agree1Accepted.
ApplicationHandleResult.Reject-1Rejected.

The method returns the current page as FriendApplicationItem[].

Friend request fields

FriendApplicationItem contains the following fields:

FieldTypeDescription
fromUserIDstringApplicant's user ID.
fromNicknamestringApplicant's nickname.
fromFaceURLstringApplicant's avatar URL.
toUserIDstringRecipient's user ID.
toNicknamestringRecipient's nickname.
toFaceURLstringRecipient's avatar URL.
reqMsgstringMessage attached to the request.
handleResultApplicationHandleResultCurrent handling result.
handlerUserIDstringUser ID that handled the request.
handleMsgstringMessage entered when handling the request.
handleTimenumberTime when the request was handled.
createTimenumberTime when the request record was created.
exstringRequest record extension string.

Listen for friend-request changes

When a friend request changes, OnFriendApplicationAdded, OnFriendApplicationAccepted, OnFriendApplicationRejected, or OnFriendApplicationDeleted is emitted with a FriendApplicationItem:

const handleApplicationChanged = (application: FriendApplicationItem) => {
  // Update the request by fromUserID and toUserID
};
const handleApplicationDeleted = (application: FriendApplicationItem) => {
  // Remove the request by fromUserID and toUserID
};

// Add 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 a request with both fromUserID and toUserID. Remove these listeners when logging out, switching accounts, or tearing down the request-list state.