• UIKit
  • SDK
  • 서버 API
Chat/
SDK/
Android/
사용자/
SDK
  • Chat SDK 설치
  • Chat SDK 초기화
  • 로그인 및 로그아웃
  • 메시지
    • 개요
    • 메시지 보내기
    • 메시지 받기
    • 메시지 검색
    • 메시지 전달
    • 메시지 수정
    • 삽입 메시지
    • 메시지 삭제
    • 과거 메시지 비우기
    • 메시지 철회
    • 온라인 메시지 보내기
    • 메시지 읽음 확인
    • 메시지 조회
    • 알림
    • 지향적 그룹 메시지
    • 알림 차단
    • Key-Value 확장
    • 반응
    • 번역
    • 메시지 최상단 고정
  • 대화
    • 개요
    • 대화 목록
    • 대화 획득
    • 읽지 않은 메시지 수
    • 대화 최상단 고정
    • 대화 삭제
    • 초안
    • 마크
    • 대화 그룹
  • 그룹
    • 개요
    • 그룹 관리
    • 정보
    • 멤버 관리
    • 멤버 정보
    • 속성
    • 카운터
  • 커뮤니티 및 화제
    • 커뮤니티 관리
    • 권한 그룹
  • 사용자
    • 사용자 정보
    • 사용자 상태
    • 친구 관리
    • 친구 그룹화
    • 블록리스트
    • Follow
  • 국부 검색
    • 메시지 검색
    • 친구 검색
    • 그룹 검색
    • 그룹 멤버 검색
  • 시그널링
  • 인터페이스 참고 문서
    • Java
  • Guideline for Beginners
  • 콘솔 안내
    • 애플리케이션 생성 및 업그레이드
    • 기본 구성
    • 기능 구성
    • 계정 관리
    • 그룹 관리
    • 콜백 구성
  • 제품 소개
    • 메시지 관리
      • 1대1 메시지
      • 메시지 저장
      • 오프라인 푸시
      • 그룹 메시지
      • 메시지 포맷
    • 계정 시스템
      • 로그인 인증
      • 온라인 상태 관리
    • 그룹 관련
      • 그룹 시스템
      • 그룹 관리
    • 사용자 정보 및 관계망
      • 정보 관리
      • 관계망 관리
  • 구매 가이드
    • 과금 개요
    • 가격
  • 에러코드
이 페이지는 현재 영어로만 제공되며 한국어 버전은 곧 제공될 예정입니다. 기다려 주셔서 감사드립니다.

블록리스트

Feature Description

To block a user's messages, add the user to the blocklist.

Blocklists

Blocking a user

Call addToBlackList (Android / iOS and Mac / Windows) to add a user to the blocklist, that is, block the user. If you have called addFriendListener to add a listener, blocking a user will trigger the onBlackListAdded callback.
Note:
If users A and B are friends, after either user A or user B is blocked by the other user, the two-way friend relationship will be terminated, and they cannot start a conversation with or send a friend request to each other.
By default, a blocked user does not know that he/she is "blocked". After the user sends a message, the error code indicating that he/she has been blocked will not be returned. To have the "You have been blocked by the user" error message returned after a blocked user sends a message, you can log in to the Console and disable Blocklist Check as shown below. Then the SDK will report error code 20007 after a blocked user sends a message.The configuration path is: Applications > Your App > Chat > Configuration > Login and Message > Blocklist Check.
Sample code:
Android
iOS and macOS
Windows
List<String> userIDList = new ArrayList<>();
userIDList.add("user1");
userIDList.add("user2");
V2TIMManager.getFriendshipManager().addToBlackList(userIDList, new V2TIMValueCallback<List<V2TIMFriendOperationResult>>() {
@Override
public void onSuccess(List<V2TIMFriendOperationResult> v2TIMFriendOperationResults) {
// User blocked successfully
}

@Override
public void onError(int code, String desc) {
// Failed to block the user
}
});

// Listen for the notification of a user added to the blocklist
V2TIMManager.getFriendshipManager().addFriendListener(new V2TIMFriendshipListener() {
@Override
public void onBlackListAdd(List<V2TIMFriendInfo> infoList) {
// A user was added to the blocklist.
}
});
// Block a user
[[V2TIMManager sharedInstance] addToBlackList:@[@"user1", @"user2"] succ:^(NSArray<V2TIMFriendOperationResult *> *resultList) {
// User blocked successfully
} fail:^(int code, NSString *desc) {
// Failed to block the user
}];

// Listen for the notification of a user added to the blocklist
[[V2TIMManager sharedInstance] addFriendListener:self];
- (void)onBlackListAdded:(NSArray<V2TIMFriendInfo *>*)infoList {
// A user was added to the blocklist.
}
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

V2TIMStringVector userIDList;
userIDList.PushBack(u8"user1");
userIDList.PushBack(u8"user2");

auto callback = new ValueCallback<V2TIMFriendOperationResultVector>{};
callback->SetCallback(
[=](const V2TIMFriendOperationResultVector& friendOperationResultList) {
// User blocked successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to block the user
delete callback;
});

V2TIMManager::GetInstance()->GetFriendshipManager()->AddToBlackList(userIDList, callback);

// Listen for the notification of a user added to the blocklist
class FriendshipListener final : public V2TIMFriendshipListener {
public:
void OnBlackListAdded(const V2TIMFriendInfoVector& infoList) override {
// A user was added to the blocklist.
}
// Other members …
};
// Add a relationship chain event listener. Keep `friendshipListener` valid before the listener is removed to ensure event callbacks are received.
FriendshipListener friendshipListener;
V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);

Unblocking a user

Call deleteFromBlackList (Android / iOS and Mac / Windows) to remove a user from the blocklist, that is, unblock the user, after which the user can send a friend request and start a conversation. If you have called addFriendListener to add a listener, unblocking a user will trigger the onBlackListDeleted callback.
Sample code:
Android
iOS and macOS
Windows
List<String> userIDList = new ArrayList<>();
userIDList.add("user1");
userIDList.add("user2");
V2TIMManager.getFriendshipManager().deleteFromBlackList(userIDList, new V2TIMValueCallback<List<V2TIMFriendOperationResult>>() {
@Override
public void onSuccess(List<V2TIMFriendOperationResult> v2TIMFriendOperationResults) {
// User unblocked successfully
}

@Override
public void onError(int code, String desc) {
// Failed to unblock the user
}
});

// Listen for the notification of a user removed from the blocklist
V2TIMManager.getFriendshipManager().addFriendListener(new V2TIMFriendshipListener() {
@Override
public void onBlackListDeleted(List<String> userList) {
// A user was removed from the blocklist.
}
});
// Unblock a user
[[V2TIMManager sharedInstance] deleteFromBlackList:@[@"user1", @"user2"] succ:^(NSArray<V2TIMFriendOperationResult *> *resultList) {
// User unblocked successfully
} fail:^(int code, NSString *desc) {
// Failed to unblock the user
}];

// Listen for the notification of a user removed from the blocklist
[[V2TIMManager sharedInstance] addFriendListener:self];
- (void)onBlackListDeleted:(NSArray*)userIDList {
// A user was removed from the blocklist.
}

template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

V2TIMStringVector userIDList;
userIDList.PushBack(u8"user1");
userIDList.PushBack(u8"user2");

auto callback = new ValueCallback<V2TIMFriendOperationResultVector>{};
callback->SetCallback(
[=](const V2TIMFriendOperationResultVector& friendOperationResultList) {
// User unblocked successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to unblock the user
delete callback;
});

V2TIMManager::GetInstance()->GetFriendshipManager()->DeleteFromBlackList(userIDList, callback);

// Listen for the notification of a user removed from the blocklist
class FriendshipListener final : public V2TIMFriendshipListener {
public:
void OnBlackListAdded(const V2TIMFriendInfoVector& infoList) override {
// A user was removed from the blocklist.
}
// Other members …
};
// Add a relationship chain event listener. Keep `friendshipListener` valid before the listener is removed to ensure event callbacks are received.
FriendshipListener friendshipListener;
V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);

Getting a blocklist

Call getBlackList (Android / iOS and Mac / Windows) to view how many users have been blocked and manage them.
Sample code:
Android
iOS and macOS
Windows
V2TIMManager.getFriendshipManager().getBlackList(new V2TIMValueCallback<List<V2TIMFriendInfo>>() {
@Override
public void onSuccess(List<V2TIMFriendInfo> v2TIMFriendInfos) {
// Blocklist obtained successfully
}

@Override
public void onError(int code, String desc) {
// Failed to obtain the blocklist
}
});
// Obtain a blocklist
[[V2TIMManager sharedInstance] getBlackList:^(NSArray<V2TIMFriendInfo *> *infoList) {
// Blocklist obtained successfully
} fail:^(int code, NSString *desc) {
// Failed to obtain the blocklist
}];
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
public:
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
}

void OnSuccess(const T& value) override {
if (success_callback_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

auto callback = new ValueCallback<V2TIMFriendInfoVector>{};
callback->SetCallback(
[=](const V2TIMFriendInfoVector& friendInfoList) {
// Blocklist obtained successfully
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// Failed to obtain the blocklist
delete callback;
});

V2TIMManager::GetInstance()->GetFriendshipManager()->GetBlackList(callback);