Skip to main content
Events enable a decoupled, flexible architecture in the CometChat UI Kit. Components emit events via the CometChatEvents singleton, and other parts of your application collect these SharedFlow streams to react without direct references between components.

When to use this

  • You need to update your UI when a user is blocked or unblocked.
  • You need to respond to group actions such as member joins, kicks, bans, or ownership transfers.
  • You need to track conversation deletions or updates in real time.
  • You need to react to messages being sent, edited, deleted, or read.
  • You need to handle call lifecycle events (outgoing, accepted, rejected, ended).
  • You need to respond to UI-level events such as panel visibility changes or active chat changes.

Prerequisites

  • The com.cometchat:chatuikit-kotlin-android or com.cometchat:chatuikit-compose-android dependency added to your project.
  • CometChatUIKit.init() called and completed successfully.
  • A logged-in CometChat user (call CometChatUIKit.login() before collecting events).

CometChatEvents Singleton

All events are accessed through the CometChatEvents singleton in chatuikit-core. Each domain has a dedicated SharedFlow that emits sealed class event types:

API reference

Message Events

CometChatEvents.messageEvents emits MessageEvent sealed class instances when messages are sent, edited, deleted, or read. Event types: Collecting events:
What this does: Collects the messageEvents SharedFlow and pattern-matches on the sealed class to handle each message lifecycle event.

Call Events

CometChatEvents.callEvents emits CallEvent sealed class instances for call lifecycle changes. Event types: Collecting events:

Conversation Events

CometChatEvents.conversationEvents emits ConversationEvent sealed class instances when conversations are deleted or updated. Event types: Collecting events:

Group Events

CometChatEvents.groupEvents emits GroupEvent sealed class instances when the logged-in user performs group-related actions. Event types: Collecting events:

User Events

CometChatEvents.userEvents emits UserEvent sealed class instances when the logged-in user blocks or unblocks another user. Event types: Collecting events:

UI Events

CometChatEvents.uiEvents emits CometChatUIEvent sealed class instances for UI-level actions such as panel visibility and active chat changes. Event types: Collecting events:
About CardActionClicked: The UI Kit renders card bubbles automatically (CometChatCardBubble) and emits this event when a user taps an action inside one — so a single subscriber handles every card action across your app. event.message is a CardMessage for standalone card messages and an AIAssistantMessage for cards embedded in AI agent replies. event.actionEvent is typed Any; import and cast it to com.cometchat.cards.actions.CometChatCardActionEvent to read its action, elementId, and cardJson.

Lifecycle Management

Since SharedFlow collection is coroutine-based, lifecycle management is handled automatically:
  • In XML Views, use lifecycleScope.launch — the coroutine is cancelled when the lifecycle owner is destroyed.
  • In Jetpack Compose, use LaunchedEffect — the coroutine is cancelled when the composable leaves the composition.
No manual removeListener calls are needed, unlike the old static listener pattern.

Next steps

Methods Reference

UI Kit wrapper methods for initialization, authentication, and sending messages

Conversations

Display and manage the conversation list, which reacts to conversation events

Message List

Display messages in a chat, which reacts to message events