Skip to main content
// Block users
await CometChat.blockUsers(["UID1", "UID2"]);

// Unblock users
await CometChat.unblockUsers(["UID1", "UID2"]);

// Get blocked users list
let request = new CometChat.BlockedUsersRequestBuilder().setLimit(30).build();
let blockedUsers = await request.fetchNext();
Directions: BLOCKED_BY_ME | HAS_BLOCKED_ME | BOTH (default)

Block Users

Block users to prevent all communication with them. Use blockUsers() with an array of UIDs.
const usersList = ["UID1", "UID2", "UID3"];

CometChat.blockUsers(usersList).then(
list => {
  console.log("users list blocked", { list });
}, error => {
  console.log("Blocking user fails with error", error);
}
);
Returns an object with UIDs as keys and "success" or "fail" as values. The method returns an array of User objects with the blockedByMe field set to true. Access the response data using getter methods:
FieldGetterReturn TypeDescription
uidgetUid()stringUnique user ID
namegetName()stringDisplay name of the user
blockedByMegetBlockedByMe()booleanWhether the logged-in user has blocked this user
hasBlockedMegetHasBlockedMe()booleanWhether this user has blocked the logged-in user

Unblock Users

Unblock previously blocked users using unblockUsers() with an array of UIDs.
const usersList = ["UID1", "UID2", "UID3"];

CometChat.unblockUsers(usersList).then(
list => {
  console.log("users list unblocked", { list });
}, error => {
  console.log("unblocking user fails with error", error);
}
);
Returns an object with UIDs as keys and "success" or "fail" as values. The method returns an array of User objects with the blockedByMe field set to false. Access the response data using getter methods:
FieldGetterReturn TypeDescription
uidgetUid()stringUnique user ID
namegetName()stringDisplay name of the user
blockedByMegetBlockedByMe()booleanWhether the logged-in user has blocked this user
hasBlockedMegetHasBlockedMe()booleanWhether this user has blocked the logged-in user

Get List of Blocked Users

Use BlockedUsersRequestBuilder to fetch blocked users with filtering and pagination.

Set Limit

Sets the number of blocked users to fetch per request.
let limit = 30;
let blockedUsersRequest = new CometChat.BlockedUsersRequestBuilder()
                  				.setLimit(limit)
                  				.build();

Set Search Keyword

Filters blocked users by a search string.
let limit = 30;
let searchKeyword = "super";
let blockedUsersRequest = new CometChat.BlockedUsersRequestBuilder()
                  				.setLimit(limit)
                  				.setSearchKeyword(searchKeyword)
                  				.build();

Set Direction

Filters by block direction:
  • BLOCKED_BY_ME — Users blocked by the logged-in user
  • HAS_BLOCKED_ME — Users who have blocked the logged-in user
  • BOTH — Both directions (default)
let limit = 30;
let blockedUsersRequest = new CometChat.BlockedUsersRequestBuilder()
  .setLimit(limit)
  .setDirection(CometChat.BlockedUsersRequest.directions.BLOCKED_BY_ME)
  .build();
After configuring the builder, call build() to get the BlockedUsersRequest object, then call fetchNext() to retrieve blocked users.
const limit = 30;
const blockedUsersRequest = new CometChat.BlockedUsersRequestBuilder()
                  				.setLimit(limit)
                  				.build();
blockedUsersRequest.fetchNext().then(
userList => {
  console.log("Blocked user list received:", userList);
}, error => {
  console.log("Blocked user list fetching failed with error:", error);
}
);

Next Steps

Retrieve Users

Fetch and filter user lists

User Presence

Track online/offline status of users

User Management

Create, update, and delete users

Flag Message

Report inappropriate messages from users