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

친구 관리

Feature Description

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

Getting contacts

The IM SDK supports the logic for the friend relationship chain. You can call the getFriendList API (Details) to get contacts.
Sample code:
// Get contacts
const friendsList = await friendshipManager.getFriendList();

Adding a friend

Call the addFriend API (Details) to add a friend.
Sample code:
// Add a two-way friend
const userID = "userID";
const remark = "Friending remarks";
const addWording = "Remarks";
const addType = FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH;
const addFriend = await friendshipManager.addFriend(
userID,
remark,
addWording,
addType
);
The process has the following variations depending on whether friend verification is required.

Option 1. Friend request approval is not required

1. Users A and B call setFriendListener to set the relationship chain listener.
2. User B specifies that friend request approval is not required (V2TIM_FRIEND_ALLOW_ANY) through the allowType field (Details) in the setSelfInfo function.
3. User A can add user B as a friend successfully by calling addFriend, after which the addType of the V2TIMFriendAddApplication request parameter can be set to either value as needed:
If it is set to V2TIM_FRIEND_TYPE_BOTH (two-way friend), both users A and B will receive the onFriendListAdded callback (Details).
If it is set to V2TIM_FRIEND_TYPE_SINGLE (one-way friend), only user A will receive the onFriendListAdded callback.

Option 2. Friend request approval is required

1. Users A and B call setFriendListener to set the relationship chain listener.
2. User B specifies that friend request approval is required (V2TIM_FRIEND_NEED_CONFIRM) through the allowType field in the setSelfInfo function.
3. User A calls addFriend to request to add user B as a friend. The resultCode parameter in the callback for successful API call returns 30539, indicating that the request needs to be approved by user B. In addition, both users A and B will receive the onFriendApplicationListAdded callback (Details).
4. User B will receive the onFriendApplicationListAdded callback. If type in the V2TIMFriendApplication parameter is V2TIM_FRIEND_APPLICATION_COME_IN, user B can accept or reject the request.
User B calls acceptFriendApplication (Details) to accept the friend request. If the type is V2TIM_FRIEND_ACCEPT_AGREE (one-way friend):
User A will receive the onFriendListAdded callback, indicating that the one-way friend was added successfully.
User B will receive the onFriendApplicationListDeleted callback (Details). At this point, user B has become a friend of user A, but not vice versa.
User B calls acceptFriendApplication to accept the friend request. If the type is V2TIM_FRIEND_ACCEPT_AGREE_AND_ADD (two-way friend), both users A and B will receive the onFriendListAdded callback, indicating that they added each other as a friend successfully.
User B calls refuseFriendApplication (Details) to reject the friend request, and both users will receive the onFriendApplicationListDeleted callback.

Deleting a friend

Call the deleteFromFriendList API (Details) to delete a friend.
Sample code:
// Delete a two-way friend
const userIDList = ["user1"];
const deleteType = FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH;
const deleteres = await friendshipManager.deleteFromFriendList(
userIDList,
deleteType
);

Checking the friend relationship

Call the checkFriend API (Details) to check the friend relationship.
Sample code:
// Check whether the friend relationship is one-way or two-way
const checkType = FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH;
const userIDList = [];
const checkres = await friendshipManager.checkFriend(userIDList, checkType);

Setting to send messages to friends only

By default, IM 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. To implement "adding a friend before sending a message" like WeChat or QQ, you can log in to the IM console, select Feature Configuration > Login and Message > Relationship Check, and enable Check Relationship for One-to-One Messages. After it is enabled, a user can send messages only to friends. If the user sends a message to a non-friend user, the SDK will report error code 20009.