please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Web/
User Profile and Relationship Chain/
SDK
  • Install Chat SDK
  • Initialize Chat SDK
  • Login and Logout
  • Client APIs
  • Changelog
  • Message
    • Overview
    • Send a Message
    • Receive a Message
    • Historical Message
    • Forward Messages
    • Modify a Message
    • Delete Messages
    • Clear History Message
    • Recall a Message
    • Send an Online Message
    • Message Read Receipt
    • Query Messages
    • Targeted Group Message
    • Do not Notify
    • Key-Value Extensions
    • Translation
  • Conversation
    • Overview
    • Conversation List
    • Get Conversations
    • Unread Count
    • Pin Conversations
    • Delete Conversations
    • Mark
    • Conversation Group
  • Group
    • Overview
    • Group Management
    • Group Profile
    • Group Member Management
    • Group Member Profile
    • Custom Group Attribute
    • Group Counter
  • Community Topic
    • Community Management
  • User Profile and Relationship Chain
    • User Profile
    • User Status
    • Friend Management
    • Friend Group
    • Block List
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Block List

Feature Description

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

Blocking a user

By adding a user to the blocklist, you can block all the messages sent by the user. Therefore, this API can be used to block the messages of a specified user.
If user A and user B are friends, the two-way friend relationship is terminated when either A or B is blocked by the other user.
If either user A or user B is blocked by the other user, neither user A nor user B can start a conversation with the other user.
If either user A or user B is blocked by the other user, neither user A nor user B can send a friend request to the other user.
API
chat.addToBlacklist(options);
Parameter
The options parameter is of the Object type. It contains the following attribute values:
Name
Type
Description
userIDList
Array
List of userID values of the users to be added to the blocklist. The number of userID values cannot exceed 1,000 per request.
Returned value
Promise
Sample
let promise = chat.addToBlacklist({userIDList: ['user1', 'user2']});
promise.then(function(imResponse) {
console.log(imResponse.data);
console.warn('addToBlacklist error:', imError); // Failed to add the user to the blocklist
});

Unblocking a user

After a user is removed from the blocklist, messages from the user can be received.
API
chat.removeFromBlacklist(options);
Parameter
The options parameter is of the Object type. It contains the following attribute values:
Name
Type
Description
userIDList
Array
List of userID values of the users to be removed from the blocklist. The number of userID values cannot exceed 1,000 per request.
Returned value
Promise
Sample
let promise = chat.removeFromBlacklist({userIDList: ['user1', 'user2']});
console.log(imResponse.data);
console.warn('removeFromBlacklist error:', imError); // Failed to remove the user from the blocklist
});

Getting the blocklist

The blocklist cached in the SDK can be obtained. When a friend list is updated, the SDK will deliver the TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED event.
API
chat.getBlacklist();
Returned value
Promise
Sample
let promise = chat.getBlacklist();
promise.then(function(imResponse) {
console.log(imResponse.data);
}).catch(function(imError) {
console.warn('getBlacklist error:', imError); // Failed to obtain the blocklist
});

Notification of a change in the blocklist

Sample
let onBlacklistUpdated = function(event) {
console.log(event.data);
};
chat.on(TencentCloudChat.EVENT.BLACKLIST_UPDATED, onBlacklistUpdated);