Skip to main content

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 CometChatProvider setup with valid credentials
  • An existing one-on-one chat screen using CometChatMessageList and CometChatMessageComposer

Components Used

Step 1: Block User

Call CometChat.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

Call CometChat.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 a CometChatConfirmDialog before blocking. Render it conditionally based on a showBlockDialog state flag. File: ChatView.tsx

Step 4: Listen for Block/Unblock Events

Use useCometChatEvents 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). File: ChatView.tsx

Step 5: Blocked Composer State

Conditionally render the composer or a blocked prompt based on the isBlocked state. The blocked prompt includes an inline unblock action. File: ChatView.tsx

Complete Example

File: ChatView.tsx

Next Steps