Relationship Chain APIs

Last updated: 2021-01-05 10:10:37

    For more information about relationship chains, see Introduction to the Relationship Chain System.

    TIMFriendshipGetFriendProfileList

    This API is used to obtain the friend list.

    Prototype

    TIM_DECL int TIMFriendshipGetFriendProfileList(TIMCommCallback cb, const void* user_data);

    Parameters

    Parameter Type Description
    cb TIMCommCallback Callback for notifying whether the friend list is obtained. For more information about the callback function definition, see TIMCommCallback.
    user_data const void* User-defined data. The IM SDK only transfers the user data to the callback function cb without processing the data.

    Return values

    Type Description
    int If TIM_SUCC is returned, the API was successfully called. (The callback cb is called only when the API returns TIM_SUCC.) If other values are returned, the API failed to be called. For more information about the definition of each return value, see TIMResult.

    Note:

    The callback set by this API returns all friend profiles. For more information, see FriendProfile.

    TIMFriendshipAddFriend

    This API is used to add friends.

    Prototype

    TIM_DECL int TIMFriendshipAddFriend(const char* json_add_friend_param, TIMCommCallback cb, const void* user_data);

    Parameters

    Parameter Type Description
    json_add_friend_param const char* JSON string of the API parameter for adding a friend.
    cb TIMCommCallback Callback for notifying whether a friend is added. For more information about the callback function definition, see TIMCommCallback.
    user_data const void* User-defined data. The IM SDK only transfers the user data to the callback function cb without processing the data.

    Return values

    Type Description
    int If TIM_SUCC is returned, the API was successfully called. (The callback cb is called only when the API returns TIM_SUCC.) If other values are returned, the API failed to be called. For more information about the definition of each return value, see TIMResult.

    Note:

    Friend relationships are classified as two-way friends and one-way friends. For more information, see Adding friends.

    Example

    Json::Value json_add_friend_param;
    json_add_friend_param[kTIMFriendshipAddFriendParamIdentifier] = "user4";
    json_add_friend_param[kTIMFriendshipAddFriendParamFriendType] = FriendTypeBoth;
    json_add_friend_param[kTIMFriendshipAddFriendParamAddSource] = "Windows";
    json_add_friend_param[kTIMFriendshipAddFriendParamAddWording] = "I am Iron Man";
    int ret = TIMFriendshipAddFriend(json_add_friend_param.toStyledString().c_str(), [](int32_t code, const char* desc, const char* json_params, const void* user_data) {
        if (ERR_SUCC != code) {
            // Failed to add a friend.
            return;
        }
    }, nullptr);

    TIMFriendshipHandleFriendAddRequest

    This API is used to process friend requests.

    Prototype

    TIM_DECL int TIMFriendshipHandleFriendAddRequest(const char* json_handle_friend_add_param, TIMCommCallback cb, const void* user_data);

    Parameters

    Parameter Type Description
    json_handle_friend_add_param const char* JSON string of the API parameter for processing friend requests.
    cb TIMCommCallback Callback for notifying whether a friend request is processed. For more information about the callback function definition, see TIMCommCallback.
    user_data const void* User-defined data. The IM SDK only transfers the user data to the callback function cb without processing the data.

    Return values

    Type Description
    int If TIM_SUCC is returned, the API was successfully called. (The callback cb is called only when the API returns TIM_SUCC.) If other values are returned, the API failed to be called. For more information about the definition of each return value, see TIMResult.

    Note:

    If kTIMUserProfileAddPermission is set to kTIMProfileAddPermission_NeedConfirm in your profile, you will receive a friend request when someone adds you as a friend. You can process the request through this API.

    Example

    Json::Value json_handle_friend_add_param;
    json_handle_friend_add_param[kTIMFriendResponeIdentifier] = "user1";
    json_handle_friend_add_param[kTIMFriendResponeAction] = ResponseActionAgreeAndAdd;
    json_handle_friend_add_param[kTIMFriendResponeRemark] = "I am Captain China";
    json_handle_friend_add_param[kTIMFriendResponeGroupName] = "schoolmate";
    int ret = TIMFriendshipHandleFriendAddRequest(json_handle_friend_add_param.toStyledString().c_str(), [](int32_t code, const char* desc, const char* json_params, const void* user_data) {
    
    }, nullptr);

    TIMFriendshipModifyFriendProfile

    This API is used to update a friend's profile (such as remarks).

    Prototype

    TIM_DECL int TIMFriendshipModifyFriendProfile(const char* json_modify_friend_info_param, TIMCommCallback cb, const void* user_data);

    Parameters

    Parameter Type Description
    json_modify_friend_info_param const char* JSON string of the API parameter for updating a friend's profile.
    cb TIMCommCallback Callback for notifying whether a friend's profile is updated. For more information about the callback function definition, see TIMCommCallback.
    user_data const void* User-defined data. The IM SDK only transfers the user data to the callback function cb without processing the data.

    Return values