Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

// Block users
CometChat.blockUsers(["UID1", "UID2"],
    onSuccess: { print("Blocked") }, onError: { error in })

// Unblock users
CometChat.unblockUsers(["UID1", "UID2"],
    onSuccess: { users in }, onError: { error in })

// Get blocked users list
let request = BlockedUserRequest.BlockedUserRequestBuilder.set(limit: 30).build()
request.fetchNext(onSuccess: { users in }, onError: { error in })
Directions: .byMe | .me | .both (default)
Blocking a user prevents all communication between them and the logged-in user — messages, calls, and presence updates are all suppressed. You can block and unblock users by UID, and fetch the blocked users list with filtering and pagination.

Block Users

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

CometChat.blockUsers(blockUsers, onSuccess: {
                
   print("Blocked user successfully.")
                
}, onError: { (error) in
                
   print("Blocked user failed with error: \\(error?.errorDescription)")
                
})
Returns a dictionary with UIDs as keys and "success" or "fail" as values based on if the block operation for each UID was successful.

Unblock Users

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

CometChat.unblockUsers(unblockUsers, onSuccess: { (users) in
                
   print("Unblocked user successfully.")
                
}, onError: { (error) in
                
   print("Unblocked user failed with error: \\(error?.errorDescription)")
                
})
Returns a dictionary with UIDs as keys and "success" or "fail" as values based on if the unblock operation for each UID was successful.

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 blockedUserRequest = BlockedUserRequest.BlockedUserRequestBuilder.set(limit: 20).build();

Set Search Keyword

Filters blocked users by a search string.
let blockedUserRequest = BlockedUserRequest.BlockedUserRequestBuilder
.set(searchKeyword: "abc")
.set(limit: 20)
.build();

Set Direction

Filters by block direction:
  • .byMe — Users blocked by the logged-in user
  • .me — Users who have blocked the logged-in user
  • .both — Both directions (default)
let blockedUserRequest = BlockedUserRequest.BlockedUserRequestBuilder
.set(searchKeyword: "abc")
.set(limit: 20)
.set(direction: .both)
.build();
After configuring the builder, call build() to get the BlockedUsersRequest object, then call fetchNext() to retrieve blocked users.
let blockedUserRequest = BlockedUserRequest.BlockedUserRequestBuilder(limit: 20).build();

blockedUserRequest.fetchNext(onSuccess : { (users) in
            
   print("Blocked users: \\(users)")
            
}, onError : { (error) in
            
   print("Error while fetching the blocked user request:  \\(error?.errorDescription)")

})
The fetchNext() method returns an array of User objects representing blocked users. Relevant fields to access on returned users:
FieldTypeDescription
blockedByMeBoolWhether the logged-in user has blocked this user
hasBlockedMeBoolWhether this user has blocked the logged-in user

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