Goal
By the end of this guide you will have a chat interface where users can block and unblock other users, with a confirmation dialog before blocking, the composer automatically hidden for blocked users, and an unblock prompt displayed in its place — all coordinated through UI events so every component stays in sync.Prerequisites
- Completed the Integration Guide guide
- A running
CometChatProvidersetup with valid credentials - An existing one-on-one chat screen using
CometChatMessageListandCometChatMessageComposer
Components Used
Step 1: Block User
CallCometChat.blockUsers() with the target UID. On success, update the user object and publish the ui:user/blocked event so other components (thread panel, details panel) can react.
File: ChatView.tsx
Step 2: Unblock User
CallCometChat.unblockUsers() to reverse the block. Publish ui:user/unblocked so all listening components restore their normal state.
File: ChatView.tsx
Step 3: Confirmation Dialog
Show aCometChatConfirmDialog before blocking. Render it conditionally based on a showBlockDialog state flag.
File: ChatView.tsx
Step 4: Listen for Block/Unblock Events
UseuseCometChatEvents to subscribe to block/unblock events. This keeps the composer visibility in sync even when the block action originates from a different component (e.g., a details panel).
The
ui:user/blocked and ui:user/unblocked events are part of the UI Kit’s Event System. See that page for the full list of user and group action events and the usePublishEvent / useCometChatEvents hooks.Step 5: Blocked Composer State
Conditionally render the composer or a blocked prompt based on theisBlocked state. The blocked prompt includes an inline unblock action.
File: ChatView.tsx
Complete Example
File: ChatView.tsxNext Steps
- Event System — full reference for the
ui:user/*events and pub/sub hooks - Message Composer — learn about composer customization
- Conversations — build a full conversations list
- CometChatProvider — configure the root provider