Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app xIncludes Enterprise features

Get received friend applications

Query friend applications received by the authenticated user with pagination.

Copy

Invoke getFriendApplicationListAsRecipient() to retrieve a paginated list of incoming friend requests sent to the authenticated user. While offset and count can be omitted, specify them explicitly starting with offset: 0 for predictable pagination.

Parameters

ParameterTypeRequiredDescription
offsetnumberNoPagination offset index; pass 0 for the first page.
countnumberNoNumber of application records to fetch per page.

This API does not accept a handleResults filter parameter. If your UI needs to display only pending, accepted, or rejected applications, filter the fetched array in your application layer using handleResult.

Code example

import { getFriendApplicationListAsRecipient } from '@/uni_modules/unix-openim-sdk'

const result = await getFriendApplicationListAsRecipient({
  offset: 0,
  count: 20,
})
const applications = result?.applications ?? []

Return value

The Promise resolves with an OpenIMFriendApplicationListResult | null object containing an array of OpenIMFriendApplicationItem elements in applications:

PropertyTypeDescription
fromUserIDstringThe user ID of the applicant who submitted the request.
fromNicknamestringThe applicant's display nickname saved with the application.
fromFaceURLstringThe applicant's avatar URL saved with the application.
toUserIDstringThe user ID of the recipient (the active account).
toNicknamestringThe recipient's display nickname saved with the application.
toFaceURLstringThe recipient's avatar URL saved with the application.
reqMsgstringThe greeting or application message text.
handleResultOpenIMApplicationHandleResultReview state: OpenIMApplicationHandleResultUnprocessed (pending), OpenIMApplicationHandleResultAccepted (approved), or OpenIMApplicationHandleResultRejected (declined).
handlerUserIDstringThe user ID who processed the request; may be empty while pending.
handleMsgstringNotes or reasons entered when processing the application.
handleTimenumberProcessing timestamp in Unix milliseconds; invalid while pending.
createTimenumberApplication creation timestamp in Unix milliseconds.
exstringApplication extension string.
attachedInfostringSDK internal metadata.

Identify a unique application record using the composite key fromUserID:toUserID. Profile attributes stored on the record represent snapshot values at the time of creation; query Get user profiles if you require the contact's live account profile.

Monitor friend application updates

Friend application lifecycle events are centrally registered here. Queries establish initial views, while events merge incremental updates. Update incoming or outgoing application lists depending on whether the current user matches toUserID or fromUserID:

import {
  OpenIMFriendApplicationItem,
  off,
  onFriendApplicationAccepted,
  onFriendApplicationAdded,
  onFriendApplicationDeleted,
  onFriendApplicationRejected,
} from '@/uni_modules/unix-openim-sdk'

const handleApplicationChanged = (
  application: OpenIMFriendApplicationItem | null,
) => {
  if (application == null) return
  mergeFriendApplication(application)
}

const handleApplicationDeleted = (
  application: OpenIMFriendApplicationItem | null,
) => {
  if (application == null) return
  removeFriendApplication(
    application.fromUserID,
    application.toUserID,
  )
}

const applicationAddedSubscription = onFriendApplicationAdded(
  handleApplicationChanged,
)
const applicationAcceptedSubscription = onFriendApplicationAccepted(
  handleApplicationChanged,
)
const applicationRejectedSubscription = onFriendApplicationRejected(
  handleApplicationChanged,
)
const applicationDeletedSubscription = onFriendApplicationDeleted(
  handleApplicationDeleted,
)

function removeFriendApplicationListeners() {
  off(applicationAddedSubscription)
  off(applicationAcceptedSubscription)
  off(applicationRejectedSubscription)
  off(applicationDeletedSubscription)
}

If application records change during active paging, reset the pagination index and re-query. When an application is approved, also update your contact roster via Get the friend list. Unregister these listeners when logging out, switching accounts, or tearing down the application view model.