AI Agent Component Spec
AI Agent Component Spec
- Package:
@cometchat/chat-uikit-react - Key components:
CometChatMessages— usesCometChat.blockUsers()/CometChat.unblockUsers()SDK methods - Required setup:
CometChatUIKit.init(UIKitSettings)thenCometChatUIKit.login("UID") - Events:
CometChatUserEvents.ccUserBlocked,CometChatUserEvents.ccUserUnblocked - UI helpers:
CometChatConfirmDialog,CometChatToast - Sample app: GitHub
- Related: All Guides
Overview
The Block Users feature allows users to prevent specific users from sending them messages, effectively cutting off communication from unwanted contacts.- Block Users feature allows users to prevent specific users from sending them messages.
- Provides privacy control, prevents harassment, and allows users to manage their communication preferences.
- Your app will allow users to block/unblock other users, hide message composers for blocked users, and provide appropriate UI feedback for blocked states.
Prerequisites
- React v18.2.0+
- CometChat React UI Kit v6.1.0+
- CometChat Chat SDK JavaScript v4.0.13+
- Project setup with initialized CometChat credentials (App ID, Auth Key, Region)
- TypeScript support (recommended)
- User authentication and chat functionality already implemented
Components
| Component / Class | Role |
|---|---|
| CometChat.blockUsers() | SDK method to block specific users |
| CometChat.unblockUsers() | SDK method to unblock previously blocked users |
| CometChatUserEvents.ccUserBlocked | Event listener for when a user is blocked |
| CometChatUserEvents.ccUserUnblocked | Event listener for when a user is unblocked |
| CometChatConfirmDialog | Confirmation dialog for block/unblock actions |
| CometChatToast | Toast notifications for action feedback |
Integration Steps
1. Block User Function Implementation
File: CometChatHome.tsx2. Unblock User Function Implementation
File: CometChatHome.tsx3. Block User Confirmation Dialog
File: CometChatHome.tsx4. Message Composer Blocked State
File: CometChatMessages.tsxImplementation Flow
- Fetch Data / User State
- Load Blocked Status / Associated Data
- Send Block/Unblock Action Handler
- Live Updates / Observers
Customization Options
- Styling overrides for blocked states and confirmation dialogs
- Custom block/unblock confirmation messages
- Toast notification customization
- Custom action items for different user states
- Custom blocked state UI
Filtering / Edge Cases
- Detect when blocking status changes mid-chat
- Prevent duplicate block actions
- Handle blocked users in search results
- Respect group chat rules when blocking
- Keep old messages visible from blocked users
Error Handling
- Handle block/unblock network errors
- Provide retry options
- Maintain UI consistency on errors
Context-Specific Notes
- Blocking applies only to private chats, not groups
- Blocked users may still appear in lists but with indicators
- Existing messages remain visible
- Updates are reflected in real-time
Summary / Feature Matrix
| Feature | Component / Method | File Reference |
|---|---|---|
| Block user | CometChat.blockUsers([UID]) | CometChatHome.tsx |
| Unblock user | CometChat.unblockUsers([UID]) | CometChatHome.tsx |
| Check blocked status | user.getBlockedByMe() | CometChatMessages.tsx |
| Block confirmation dlg | CometChatConfirmDialog | CometChatHome.tsx |
| Blocked composer state | message-composer-blocked | CometChatMessages.tsx |
| Block user events | ccUserBlocked.subscribe() | CometChatHome.tsx |
| Unblock user events | ccUserUnblocked.subscribe() | CometChatHome.tsx |
| Update user state | user.setBlockedByMe(boolean) | CometChatHome.tsx |
Next Steps
Users
Display and manage user lists.
Message Composer
Customize the message input component.
All Guides
Browse all feature and formatter guides.
Sample App
Full working sample application on GitHub.