• UIKit
  • SDK
  • 서버 API
Chat/
SDK/
Unity(Game Solution)/
사용자/
SDK
  • Run Demo
  • SDK 통합
  • 초기화
  • 로그인 및 로그아웃
  • 메시지
    • 메시지 개요
    • 메시지 보내기
    • 메시지 받기
    • 과거 메시지
    • 메시지 전달
    • 메시지 수정
    • 메시지 삭제
    • 메시지 비우기
    • 메시지 철회
    • 온라인 메시지
    • 읽음 확인
    • 메시지 조회
    • 그룹 @ 메시지
    • 지향적 그룹 메시지
    • 알림 음소거
    • 메시지 확장
  • 대화
    • 대화 개요
    • 대화 목록
    • 대화 획득
    • 읽지 않은 대화 수
    • 대화 최상단 고정
    • 대화 삭제
    • 대화 초안
    • 대화 마크
    • 대화 그룹
  • 그룹
    • 그룹 개요
    • 그룹 관리
    • 그룹 정보
    • 그룹 멤버 관리
    • 그룹 멤버 정보
    • 그룹 속성 사용자 정의
    • 그룹 카운터
  • 사용자
    • 사용자 정보
    • 사용자 상태
    • 친구 관리
    • 친구 목록
    • 블록리스트
  • Changelog
  • Guideline for Beginners
  • 콘솔 안내
    • 애플리케이션 생성 및 업그레이드
    • 기본 구성
    • 기능 구성
    • 계정 관리
    • 그룹 관리
    • 콜백 구성
  • 제품 소개
    • 메시지 관리
      • 1대1 메시지
      • 메시지 저장
      • 오프라인 푸시
      • 그룹 메시지
      • 메시지 포맷
    • 계정 시스템
      • 로그인 인증
      • 온라인 상태 관리
    • 그룹 관련
      • 그룹 시스템
      • 그룹 관리
    • 사용자 정보 및 관계망
      • 정보 관리
      • 관계망 관리
  • 구매 가이드
    • 과금 개요
    • 가격
  • 에러코드
이 페이지는 현재 영어로만 제공되며 한국어 버전은 곧 제공될 예정입니다. 기다려 주셔서 감사드립니다.

친구 관리

Overview

The Chat SDK supports friend management, and users can add and delete friends and set to send messages only to friends.

Getting the contacts

The Chat SDK supports the logic for the friend relationship chain. You can call the FriendshipGetFriendProfileList API (details) to get contacts.
Sample code:
// Obtain the contacts
TIMResult res = TencentIMSDK.FriendshipGetFriendProfileList((int code, string desc, List<FriendProfile> profile_list, string user_data)=>{
// Process the async logic
});

Adding friends

Call the FriendshipAddFriend API (details) to add a friend.
Sample code:
// Add a two-way friend
FriendshipAddFriendParam param = new FriendshipAddFriendParam
{
friendship_add_friend_param_identifier = "friend_userid",
friendship_add_friend_param_friend_type = TIMFriendType.FriendTypeBoth,
friendship_add_friend_param_remark = "nickname",
friendship_add_friend_param_add_wording = "greeting"
};
TIMResult res = TencentIMSDK.FriendshipAddFriend(param, (int code, string desc, FriendResult result, string user_data)=>{
// Process the async logic
});
The process has the following variations depending on whether friend request approval is required.

Friend request approval is not required

1. Users A and B call SetOnAddFriendCallback to set the relationship chain listener.
2. User B specifies that friend request approval is not required (kTIMProfileAddPermission_AllowAny) through the user_profile_item_add_permission field (details) in the ProfileModifySelfUserProfile function.
3. User A can add user B as a friend successfully by calling FriendshipAddFriend, after which the friendship_add_friend_param_friend_type of the FriendshipAddFriendParam request parameter can be set to either value as needed:
If it is set to TIMFriendType.FriendTypeBoth (two-way friend), both users A and B will receive the OnAddFriendCallback callback (details).
If it is set to TIMFriendType.FriendTypeSignle (one-way friend), only user A will receive the OnAddFriendCallback callback.

Friend request approval is required

1. Users A and B call SetOnAddFriendCallback to set the relationship chain listener.
2. User B specifies that friend request approval is required (kTIMProfileAddPermission_NeedConfirm) through the user_profile_item_add_permission field in the ProfileModifySelfUserProfile function.
3. User A calls FriendshipAddFriend to request to add user B as a friend. The code parameter in the callback for successful API call returns 30539, indicating that the request needs to be approved by user B.
4. User B will receive the SetFriendAddRequestCallback callback and can accept or reject the request.
User B calls FriendshipHandleFriendAddRequest API (details) to accept the friend request. If the type is TIMFriendResponseAction.ResponseActionAgree (one-way friend):
User A will receive the OnAddFriendCallback callback, indicating that the one-way friend was added successfully.
User B will receive the FriendApplicationListDeletedCallback callback (details). At this point, user B has become a friend of user A, but not vice versa.
User B calls FriendshipHandleFriendAddRequest to accept the friend request. If the type is TIMFriendResponseAction.ResponseActionAgreeAndAdd (two-way friend), both users A and B will receive the OnAddFriendCallback callback, indicating that they added each other as a friend successfully.
User B calls FriendshipHandleFriendAddRequest and passes in the TIMFriendResponseAction parameter to reject the friend request, and both users will receive the FriendApplicationListDeletedCallback callback.

Deleting friends

Call the FriendshipDeleteFriend API (details) to delete a friend.
Sample code:
// Two-way deletion
FriendshipDeleteFriendParam param = new FriendshipDeleteFriendParam
{
friendship_delete_friend_param_friend_type = TIMFriendType.FriendTypeBoth,
friendship_delete_friend_param_identifier_array = new List<string>
{
"user_id"
}
};
TIMResult res = TencentIMSDK.FriendshipDeleteFriend(param, (int code, string desc, FriendResult result, string user_data)=>{
// Process the async logic
});

Checking friend relationships

Call the FriendshipCheckFriendType API (details) to check the friend relationship.
Sample code:
// Check whether the friend relationship is one-way or two-way
FriendshipCheckFriendTypeParam param = new FriendshipCheckFriendTypeParam
{
friendship_check_friendtype_param_check_type = TIMFriendType.FriendTypeBoth,
friendship_check_friendtype_param_identifier_array = new List<string>{
"user_id"
}
};
TIMResult res = TencentIMSDK.FriendshipCheckFriendType(param, (int code, string desc, List<FriendshipCheckFriendTypeResult> result_list, string user_data)=>{
// Process the async logic
});

Setting to send messages to friends only

By default, Chat SDK does not check the relationship when sending one-to-one messages. This default setting is generally applied in customer service scenarios, where having to friend a customer service agent before chatting is inefficient. If you want to implement the interaction mode of “friending before chatting” as in WeChat and QQ, go to Chat console -> Feature Configuration -> Login and Message -> Relationship Check and enable "Check Relationship for One-to-One Messages". With this feature enabled, users can only send messages to friends, and will receive the 20009 error code from SDK when sending a message to a non-friend user.