Browse SDKs · uni-app / uni-app x
SDKsuni-app

List received friend requests

Read received requests and process add, accept, reject, and delete events.

Copy

getFriendApplicationListAsRecipient() queries applications sent to the current account. The uni-app / uni-app x OpenIMApplicationListParams has only pagination fields and does not expose Wasm's handleResults filter. Filter by handleResult after the query if the UI should show only pending applications.

Parameters

The parameter object can be omitted. To request an explicit page, use:

ParameterTypeRequiredDescription
offsetnumber or nullNoPagination offset; use 0 for the first page.
countnumber or nullNoNumber of applications requested.
import { getFriendApplicationListAsRecipient } from '@/uni_modules/unix-openim-sdk'

const result = await getFriendApplicationListAsRecipient({
  offset: 0,
  count: 20,
})

const applications = result?.applications ?? []
replaceReceivedApplications(applications)

The Promise resolves directly to OpenIMFriendApplicationListResult or null. applications contains the current page of OpenIMFriendApplicationItem[]; querying does not itself trigger an application event.

Friend-application fields

FieldTypeDescription
fromUserIDstringApplicant's user ID.
fromNicknamestringApplicant nickname snapshot.
fromFaceURLstringApplicant avatar snapshot.
toUserIDstringRecipient user ID.
toNicknamestringRecipient nickname snapshot.
toFaceURLstringRecipient avatar snapshot.
reqMsgstringApplication message.
handleResultnumberProcessing result: 0 pending, 1 accepted, -1 rejected.
handlerUserIDstringProcessing user ID; can be empty while pending.
handleMsgstringProcessing comment.
handleTimenumberProcessing time; do not treat it as valid while pending.
createTimenumberRecord creation time.
exstringApplication extension string.
attachedInfostringSDK attachment data; parse only a confirmed contract.

Use fromUserID:toUserID as the merge key. Nicknames and avatars are snapshots from application creation or synchronization. Query the relevant user's current profile with getUsersInfo() when freshness matters.

Synchronize friend-application changes

This page is the complete owner for the added, accepted, rejected, and deleted events. Register them before loading the snapshot.

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

const subscriptions : Array<OpenIMSDKEventSubscription> = [
  onFriendApplicationAdded((item) => mergeFriendApplication(item.fromUserID, item.toUserID, item)),
  onFriendApplicationAccepted((item) => mergeFriendApplication(item.fromUserID, item.toUserID, item)),
  onFriendApplicationRejected((item) => mergeFriendApplication(item.fromUserID, item.toUserID, item)),
  onFriendApplicationDeleted((item) => removeFriendApplication(item.fromUserID, item.toUserID)),
]
const page = await getFriendApplicationListAsRecipient({ offset: 0, count: 50 })
replaceReceivedApplications(page?.applications ?? [])

function releaseFriendApplicationSubscriptions() {
  subscriptions.forEach((subscription) => off(subscription))
  subscriptions.length = 0
}

Route an event to the sent or received list according to whether the current user is toUserID. An accepted application creates a friendship that is merged through onFriendAdded on Get the friend list. Pagination can be reset when events alter the list.

Accept or reject a received application through the corresponding API; never mutate handleResult locally to imitate server success. Call releaseFriendApplicationSubscriptions() on logout, account switch, or destruction of the friend-application state layer.