Skip to main content
Enable users to block and unblock others directly within chat using CometChat’s Android UI Kit v5+, preventing unwanted communication and giving users more control.

Overview

Blocking a user stops them from sending messages to the blocker. The CometChat UIKit handles most behaviors internally:
  • Composer Hidden: The message composer is hidden when chatting with a blocked user.
  • Unblock Prompt: An “Unblock” button is displayed to reverse the block.
  • Message Restrictions: Blocked users cannot send messages to the blocker.

Prerequisites

  • Android Studio project with CometChat Android UI Kit v5 added to build.gradle.
  • CometChat App ID, Auth Key, and Region configured and initialized.
  • <uses-permission android:name="android.permission.INTERNET"/> in AndroidManifest.xml.
  • Logged-in user via CometChatUIKit.login().
  • Existing one-on-one chat screen using CometChatMessageList and CometChatMessageComposer.

Components

Integration Steps

1. Detect Block Status

Update UI when block state changes.
File reference:
MessagesActivity.kt
Ensures the composer and unblock UI reflect the current block state.

2. Hide Composer & Show Unblock UI

Define layout elements and their visibility toggles.
activity_messages.xml
Prepares the UI containers for dynamic show/hide operations.

3. Trigger Unblock Action

Call the unblock API and observe status updates.
Executes unblock logic and updates state to refresh UI.

4. Trigger Block from Detail Screen

Allow blocking directly from a user’s profile.

Implementation Flow

Customization Options

  • Feedback UI: Show a Toast or Snackbar upon success/failure.
  • Menu Icons/Text: Toggle icon and text dynamically after block/unblock.
  • Disable History: Optionally gray out or hide past messages when blocked.

Filtering & Edge Cases

Error Handling

  • Handle errors from blockUsers and unblockUsers callbacks by showing alerts or retry prompts.
  • Ensure UI state reverts on failure.

Group vs. User-Level Differences

Summary / Feature Matrix

Next Steps & Further Reading

Android Sample App (Kotlin)

Explore this feature in the CometChat SampleApp: GitHub → SampleApp