Skip to main content
Blocking stops two people messaging each other. In a v6 app the action lives on a screen you build — a profile or a user-details page — and the Kit’s components follow it once you announce it on the event bus.

Overview

  • Your screen calls the SDK to block or unblock.
  • You set the user’s blockedByMe and emit userBlocked / userUnblocked.
  • The Kit reacts: Conversations drops the chat on a block, Users and the message header redraw the user, and the composer stops sending typing indicators.
  • Your chat screen swaps the composer for an “Unblock” bar while you have blocked the user.

Prerequisites

  • The Kit is set up and a user is logged in — see Getting Started.
  • A one-to-one chat screen with CometChatMessageHeader, CometChatMessageList and CometChatMessageComposer.

Components

Integration Steps

1. Bridge the SDK calls

The SDK calls back on its own queue. Bridge it from a nonisolated function so the callback never runs as main-actor code:
BlockActions.swift
Do not pass SDK callbacks straight from a view or a view controller. Under Swift 6 a closure written in main-actor code is main-actor isolated, and the SDK calling it on its own queue stops the app.

2. Block from your details screen, and announce it

After the SDK succeeds, mark the user and emit the event. Without the event the conversation stays in Conversations and the header shows the user as unblocked.
UserDetailsView.swift
Ask before blocking. The CometChat sample apps confirm with “Block this contact?” and then show a toast with the result.

3. Swap the composer for an unblock bar

The composer does not hide itself. While you have blocked the user, show your own bar in its place, and follow the block from anywhere in the app through the event:
BlockAwareComposer.swift
Host the composer, or your bar in its place, over the list as Conversation List + Message View shows.

4. Hide calls while either side has blocked

The message header hides its call buttons only when you ask. Use both flags — a block either way should stop calls:

Implementation Flow

  1. The user taps Block on your details screen and confirms.
  2. CometChat.blockUsers succeeds; you set blockedByMe and emit userBlocked.
  3. Conversations removes the chat, Users and the header redraw, your chat shows the unblock bar.
  4. Unblock reverses it with unblockUsers and userUnblocked; the composer returns.

Edge Cases

Group vs. User-Level Differences

Blocking is between two users. It does not remove anyone from a group: in a group chat you keep seeing a blocked user’s messages. To keep someone out of a group, ban or kick them — see Group Chat.

Feature Matrix

Next Steps

Events

Every event your screens must announce

Message Composer

The composer’s options

Block Users (SDK)

The SDK calls in full

All Guides

Browse the other guides