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 Platform Description
userID String yes All The ID of the user to be accepted as a friend.
remark String no All Give a remark to the user.
friendGroup String no All Allocate the user to a group.
addWording String no All Attached information of accepting.
addSource String no All Add the description of the adding source.
addType FriendTypeEnum yes All The type of accepting and adding, two-way friend as default.

Returned template

V2TimValueCallback<V2TimFriendOperationResult>

{
    code : int
    desc : String
    data : {
        resultCode : int
        resultInfo : String
        userID : String
    }
}

Return value details

name type description
code int 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

    V2TimValueCallback<V2TimFriendOperationResult> addFriendRes =
        await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().addFriend(
              userID: "userID", 
              remark: "", 
              friendGroup: "", 
              addWording: "", 
              addSource: "", 
              addType: FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH, 
            );
    if (addFriendRes.code == 0) {
      addFriendRes.data?.resultCode; 
      addFriendRes.data?.resultInfo; 
      addFriendRes.data?.userID; 
    }

results matching ""

    No results matching ""