searchFriends
Feature Description
Note
Search for friends in your friends list using keywords.
Caution
(1) You must specify at least one search domain. (2) Multiple domains are related by an OR logic.
- iOS
- Android
- Flutter
- uni-app
- Browser/Electron/MiniProgram
- React-Native
- Unity
Function Prototype
Future<List<SearchFriendsInfo>> searchFriends({
List<String> keywordList = const [],
bool isSearchUserID = false,
bool isSearchNickname = false,
bool isSearchRemark = false,
String? operationID,
})
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
keywordList | List<String> | Yes | Search keyword, currently only supports one keyword and can't be empty |
isSearchUserID | bool | Yes | Search by UserID? |
isSearchNickname | bool | Yes | Search by nickname? Default is false |
isSearchRemark | bool | Yes | Search by remark? Default is false |
Return Value
Parameter Name | Parameter Type | Description |
---|---|---|
~ | List<SearchFriendInfo> | Successful return |
SearchFriendInfo
Field Name | Field Type | Description |
---|---|---|
ownerUserID | String | Currently logged-in User ID |
friendUserID | String | Friend's ID |
nickname | String | Friend's nickname |
faceURL | String | Profile picture |
remark | String | Friend's remark |
createTime | int | Time of becoming friends |
addSource | int | Method of becoming friends |
operatorUserID | String | User ID who initiated the friendship |
attachedInfo | String | Not currently in use |
ex | String | Extension field |
relationship | int | 0 for blacklist, 1 for friend |
Code Example
List<SearchFriendsInfo> list= await OpenIM.iMManager.friendshipManager.searchFriends(
keywordList: ['lucy'],
isSearchNickname: true,
isSearchRemark: true,
isSearchUserID: false,
);
// todo
Function Prototype
- (void)searchFriends:(OIMSearchFriendsParam *)searchParam
onSuccess:(nullable OIMSearchUsersInfoCallback)onSuccess
onFailure:(nullable OIMFailureCallback)onFailure;
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
OIMSearchFriendsParam.keywordList | NSArray<NSString *> | Search keyword, currently only supports one keyword and can't be empty | |
OIMSearchFriendsParam.isSearchUserID | BOOL | Search by UserID? | |
OIMSearchFriendsParam.isSearchNickname | BOOL | Search by nickname? Default is false | |
OIMSearchFriendsParam.isSearchRemark | BOOL | Search by remark? Default is false |
Return Value
Parameter Name | Parameter Type | Description |
---|---|---|
onSuccess | NSArray< OIMSearchFriendsInfo * > | Successful return |
onFailure | OIMFailureCallback | Failed return |
OIMSearchFriendsInfo
Field Name | Field Type | Description |
---|---|---|
ownerUserID | NSString | Currently logged-in User ID |
friendUserID | NSString | Friend's ID |
nickname | NSString | Friend's nickname |
faceURL | NSString | Profile picture |
remark | NSString | Friend's remark |
createTime | NSInteger | Time of becoming friends |
addSource | NSInteger | Method of becoming friends |
operatorUserID | NSString | User ID who initiated the friendship |
attachedInfo | NSString | Not currently in use |
ex | NSString | Extension field |
relationship | OIMRelationship | 0 for blacklist, 1 for friend |
Code Example
OIMSearchFriendsParam *param = [OIMSearchFriendsParam new];
param.keywordList = @[];
param.isSearchRemark = YES;
param.isSearchUserID = YES;
[OIMManager.manager searchFriends:param
onSuccess:^(NSArray<OIMSearchFriendsInfo *> * _Nullable usersInfo) {
} onFailure:^(NSInteger code, NSString * _Nullable msg) {
}];
Function Prototype
public void searchFriends(OnBase<List<FriendInfo>> callBack, List<String> keywordList, boolean isSearchUserID, boolean isSearchNickname, boolean isSearchRemark)
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
callBack | OnBase<List<FriendInfo>> | Yes | Callback interface |
keywordList | List<String> | Yes | Search keyword, currently only supports one keyword and can't be empty |
isSearchUserID | Boolean | Yes | Search by UserID? |
isSearchNickname | Boolean | Yes | Search by nickname? Default is false |
isSearchRemark | Boolean | Yes | Search by remark? Default is false |
Return Value
Code Example
OpenIMClient.getInstance().friendshipManager.searchFriends(new OnBase<List<FriendInfo>>(){…},uid,keywordList,isSearchUserID,isSearchNickname,isSearchRemark)
Function Prototype
enum Relationship {
Black,
Friend
}
type SearchedFriendsInfo = FriendUserItem & {
relationship: Relationship;
};
IMSDK.searchFriends({
keywordList: string[];
isSearchUserID: boolean;
isSearchNickname: boolean;
isSearchRemark: boolean;
}, operationID?: string): Promise<WsResponse<SearchedFriendsInfo[]>>
Input Parameters
Parameter Name | Parameter Type | Required | Description |
---|---|---|---|
keywordList | string[] | Yes | Search keyword. Currently, only supports one keyword and cannot be empty. |
isSearchUserID | boolean | Yes | Search by userID using the keyword. |
isSearchNickname | boolean | Yes | Search by nickname using the keyword. |
isSearchRemark | boolean | Yes | Search by remark using the keyword. |
Return Results
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse<SearchedFriendsInfo[]>> | List of found friend information. |
Promise.catch() | Promise<WsResponse> | Callback if the call fails. |
Code Example
import { getSDK } from '@openim/wasm-client-sdk';
const IMSDK = getSDK();
// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();
// use in mini program
// import { getSDK } from '@openim/client-sdk';
// const IMSDK = getSDK();
IMSDK.searchFriends({
keywordList: ['nickname'];
isSearchUserID: false,
isSearchNickname: true,
isSearchRemark: true,
})
.then(({data}) => {
// Call was successful.
})
.catch(({ errCode, errMsg }) => {
// Call failed.
});
Function Prototype
enum Relationship {
Black,
Friend
}
type SearchedFriendsInfo = FriendUserItem & {
relationship: Relationship;
};
IMSDK.asyncApi('searchFriends', operationID: string, {
keywordList: string[];
isSearchUserID: boolean;
isSearchNickname: boolean;
isSearchRemark: boolean;
}): Promise<SearchedFriendsInfo[]>
Input Parameters
Parameter Name | Parameter Type | Required | Description |
---|---|---|---|
operationID | string | Yes | Operation ID, used for problem location. It should be unique and typically combines the current time with a random number. |
keywordList | string[] | Yes | Search keyword. Currently, only supports one keyword and cannot be empty. |
isSearchUserID | boolean | Yes | Search by userID using the keyword. |
isSearchNickname | boolean | Yes | Search by nickname using the keyword. |
isSearchRemark | boolean | Yes | Search by remark using the keyword. |
Return Results
The function is Promise-ified using the
openim-uniapp-polyfill
package. You need to usethen
andcatch
to handle success and failure callbacks respectively.
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<SearchedFriendsInfo[]> | List of found friend information. |
Promise.catch() | Promise<CatchResponse> | Callback if the call fails. |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
IMSDK.asyncApi('searchFriends', IMSDK.uuid(), {
keywordList: ['nickname'];
isSearchUserID: false,
isSearchNickname: true,
isSearchRemark: true,
})
.then((data) => {
// Call was successful.
})
.catch(({ errCode, errMsg }) => {
// Call failed.
});
Function Prototype
enum Relationship {
Black,
Friend
}
type SearchedFriendsInfo = FriendUserItem & {
relationship: Relationship;
};
OpenIMSDKRN.searchFriends({
keywordList: string[];
isSearchUserID: boolean;
isSearchNickname: boolean;
isSearchRemark: boolean;
}, operationID: string): Promise<SearchedFriendsInfo[]>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
keywordList | string[] | Yes | Search keyword. Currently, only supports one keyword and cannot be empty. |
isSearchUserID | boolean | Yes | Search by userID using the keyword. |
isSearchNickname | boolean | Yes | Search by nickname using the keyword. |
isSearchRemark | boolean | Yes | Search by remark using the keyword. |
operationID | string | Yes | Operation ID, used for problem location, keep unique, suggest using current time and random number |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<SearchedFriendsInfo[]> | List of found friend information. |
Promise.catch() | Promise<CatchResponse> | Callback on failed call |
Code Example
import OpenIMSDKRN from "open-im-sdk-rn";
OpenIMSDKRN.searchFriends({
keywordList: ['nickname'];
isSearchUserID: false,
isSearchNickname: true,
isSearchRemark: true,
}, 'operationID')
.then((data) => {
// Call was successful.
})
.catch(({ errCode, errMsg }) => {
// Call failed.
});
Function Prototype
public static void SearchFriends(OnBase<List<SearchFriendItem>> cb, SearchFriendsParam searchParam)
Input Parameter
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
cb | OnBase<List<FriendInfo>> | Yes | Callback |
searchParam | SearchFriendsParam | Yes | Search Friend Parameter |
Return Result
Code Example
IMSDK.SearchFriends((list,errCode,errMsg)=>{
},new SearchFriendsParam(){
KeywordList = {"keyword"},
IsSearchUserID = true,
IsSearchNickname = false,
IsSearchRemark = false,
});