addFriend
Introduction
Add Friend.
There are two different processes, according to the verification mode of the target user.
First: Do not need verification when accepting adding friends.
Setting a friend relationship listener with setFriendListener
, on the device of both user A and B.
User B can set the verification type to do not need verify when be added as a friend, by setting the allowType
in setSelfInfo
to V2TIM_FRIEND_ALLOW_ANY
.
User A adding B as a friend by invoking the addFriend method, following by the two processes:
If the addType
is V2TIM_FRIEND_TYPE_BOTH
, means two-way friend, both User A and User B will receive the callback of onFriendListAdded
.
If the addType
is V2TIM_FRIEND_TYPE_SINGLE
, means one-way friend, only User A will receive the callback of onFriendListAdded
.
Second: Verification is needed when adding a friend.
Setting a friend relationship listener with setFriendListener
, on the device of both user A and B.
ser B can set the verification type to do need verify when be added as a friend, by setting the allowType
in setSelfInfo
to V2TIM_FRIEND_NEED_CONFIRM
.
User A add User B as a friend, by invoking addFriend
, while receiving the resultCode
of 30539, means needs to wait the verification from the User B, while the callback of onFriendApplicationListAdded
will be invoked on both User A and User B.
User B can choose whether to accept the friend application from User A, after receiving this callback.
Choose Accept: User B calls acceptFriendApplication
to accept the friend application.
If addType
is V2TIM_FRIEND_ACCEPT_AGREE
, User A will added User B as a friend successfully, but User A still not be a friend as User B, while User A will receive the callback of onFriendListAdded
and onFriendApplicationListDeleted
.
If addType
is V2TIM_FRIEND_ACCEPT_AGREE_AND_ADD
, both User A and User B will be added as a friend of each other, and they will receive the callback of onFriendListAdded
.
Choose Refuse: User B calls refuseFriendApplication
to refuse the friend application, both User A and User B will receive the callback of onFriendApplicationListDeleted
.
Parameter details
Parameter name | Parameter type | Required | Description |
---|---|---|---|
userID | string | yes | The ID of the user to be accepted as a friend. |
remark | string | no | Give a remark to the user. |
friendGroup | string | no | Allocate the user to a group. |
addWording | string | no | Attached information of accepting. |
addSource | string | no | Add the description of the adding source. |
addType | FriendType | yes | The type of accepting and adding, two-way friend as default. |
Returned template
V2TimValueCallback<V2TimFriendOperationResult>
{
code : number
desc : string
data : {
resultCode : number
resultInfo : string
userID : string
}
}
Return value details
name | type | description |
---|---|---|
code | number | Request result: Error codes. 0 means success. |
desc | string | The description of the error. It will be empty if success. |
data | V2TimFriendOperationResult | The result of the operation. |
Code example
import { TencentImSDKPlugin, FriendType } from 'react-native-tim-js';
const addFriendRes = await TencentImSDKPlugin.v2TIMManager
.getFriendshipManager()
.addFriend(
'userID',
FriendType.V2TIM_FRIEND_TYPE_BOTH,
'remark',
'friendGroup',
'addWording',
'addSource'
);
if (addFriendRes.code === 0) {
addFriendRes.data?.resultCode;
addFriendRes.data?.resultInfo;
addFriendRes.data?.userID;
}