addToBlackList
(Android / iOS & Mac / Windows) 接口把某用户加入黑名单,即拉黑该用户。
如果您事先调用 addFriendListener
添加了监听器,拉黑后会触发 onBlackListAdded
回调。Blocklist Check
。关闭后,被拉黑的用户在发送消息时,SDK 会报 20007 错误码。配置路径为:Applications > Your App > Chat > Configuration > Login and Message > Blocklist Check。List<String> userIDList = new ArrayList<>();userIDList.add("user1");userIDList.add("user2");V2TIMManager.getFriendshipManager().addToBlackList(userIDList, new V2TIMValueCallback<List<V2TIMFriendOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFriendOperationResult> v2TIMFriendOperationResults) {// 拉黑成功}@Overridepublic void onError(int code, String desc) {// 拉黑失败}});// 监听黑名单列表新增通知V2TIMManager.getFriendshipManager().addFriendListener(new V2TIMFriendshipListener() {@Overridepublic void onBlackListAdd(List<V2TIMFriendInfo> infoList) {// 黑名单列表新增通知}});
// 拉黑某人[[V2TIMManager sharedInstance] addToBlackList:@[@"user1", @"user2"] succ:^(NSArray<V2TIMFriendOperationResult *> *resultList) {// 拉黑成功} fail:^(int code, NSString *desc) {// 拉黑失败}];// 监听黑名单列表新增通知[[V2TIMManager sharedInstance] addFriendListener:self];- (void)onBlackListAdded:(NSArray<V2TIMFriendInfo *>*)infoList {// 黑名单列表新增通知}
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) {// 拉黑成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 拉黑失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->AddToBlackList(userIDList, callback);// 监听黑名单列表新增通知class FriendshipListener final : public V2TIMFriendshipListener {public:void OnBlackListAdded(const V2TIMFriendInfoVector& infoList) override {// 黑名单列表新增通知}// 其他成员 ...};// 添加关系链事件监听器,注意在移除监听器之前需要保持 friendshipListener 的生命期,以免接收不到事件回调FriendshipListener friendshipListener;V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);
deleteFromBlackList
(Android / iOS & Mac / Windows) 将某用户从黑名单中移除,移除后可正常发起加好友请求、发起会话。
如果您事先调用 addFriendListener
添加了监听器,解除拉黑后会触发 onBlackListDeleted
回调。List<String> userIDList = new ArrayList<>();userIDList.add("user1");userIDList.add("user2");V2TIMManager.getFriendshipManager().deleteFromBlackList(userIDList, new V2TIMValueCallback<List<V2TIMFriendOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFriendOperationResult> v2TIMFriendOperationResults) {// 解除拉黑成功}@Overridepublic void onError(int code, String desc) {// 解除拉黑失败}});// 监听黑名单列表删除通知V2TIMManager.getFriendshipManager().addFriendListener(new V2TIMFriendshipListener() {@Overridepublic void onBlackListDeleted(List<String> userList) {// 黑名单列表删除通知}});
// 解除拉黑[[V2TIMManager sharedInstance] deleteFromBlackList:@[@"user1", @"user2"] succ:^(NSArray<V2TIMFriendOperationResult *> *resultList) {// 解除拉黑成功} fail:^(int code, NSString *desc) {// 解除拉黑失败}];// 监听黑名单列表删除通知[[V2TIMManager sharedInstance] addFriendListener:self];- (void)onBlackListDeleted:(NSArray*)userIDList {// 黑名单列表删除通知}
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) {// 解除拉黑成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 解除拉黑失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->DeleteFromBlackList(userIDList, callback);// 监听黑名单列表删除通知class FriendshipListener final : public V2TIMFriendshipListener {public:void OnBlackListAdded(const V2TIMFriendInfoVector& infoList) override {// 黑名单列表删除通知}// 其他成员 ...};// 添加关系链事件监听器,注意在移除监听器之前需要保持 friendshipListener 的生命期,以免接收不到事件回调FriendshipListener friendshipListener;V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);
V2TIMManager.getFriendshipManager().getBlackList(new V2TIMValueCallback<List<V2TIMFriendInfo>>() {@Overridepublic void onSuccess(List<V2TIMFriendInfo> v2TIMFriendInfos) {// 获取黑名单列表成功}@Overridepublic void onError(int code, String desc) {// 获取黑名单列表失败}});
// 获取黑名单列表[[V2TIMManager sharedInstance] getBlackList:^(NSArray<V2TIMFriendInfo *> *infoList) {// 获取黑名单列表成功} fail:^(int code, NSString *desc) {// 获取黑名单列表失败}];
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) {// 获取黑名单列表成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取黑名单列表失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetBlackList(callback);
本页内容是否解决了您的问题?