Skip to main content

Events

Overview

Events allow for a decoupled, flexible architecture where different parts of the application can interact without having to directly reference each other. This makes it easier to create complex, interactive experiences, as well as to extend and customize the functionality provided by the CometChat UI Kit.

Both Components and Composite Components have the ability to emit events. These events are dispatched in response to certain changes or user interactions within the component. By emitting events, these components allow other parts of the application to react to changes or interactions, thus enabling dynamic and interactive behavior within the application.

User Events

CometChatUserEvents emit events when the logged-in user executes actions on another user. This class provides methods to add and remove listeners for user events, as well as methods to handle specific user actions such as blocking and unblocking users.

  1. ccUserBlocked: Triggered when the logged-in user blocks another user.
  2. ccUserUnblocked: Triggered when the logged-in user unblocks another user.
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';

class UserEventsExample extends StatefulWidget {
const UserEventsExample({super.key});


State<UserEventsExample> createState() => _UserEventsExampleState();
}

class _UserEventsExampleState extends State<UserEventsExample> with CometChatUserEventListener {
String listenerID = "unique_listener_ID";


void initState() {
super.initState();

CometChatUserEvents.addUsersListener(listenerID, this); // Add the listener
}


void dispose() {
super.dispose();

CometChatUserEvents.removeUsersListener(listenerID); // Remove the listener
}


void ccUserBlocked(User user) {
// TODO("Not yet implemented")
}


void ccUserUnblocked(User user) {
// TODO("Not yet implemented")
}


Widget build(BuildContext context) {
return const Placeholder();
}
}

Group Events

CometChatGroupEvents Emits events when the logged-in user performs actions related to groups. This class provides methods to listen to various group-related events and handle them accordingly.

Following are all the group events

  1. ccGroupCreated: Triggered when the logged-in user creates a group.
  2. ccGroupDeleted: Triggered when the logged-in user deletes a group.
  3. ccGroupLeft: Triggered when the logged-in user leaves a group.
  4. ccGroupMemberScopeChanged: Triggered when the logged-in user changes the scope of another group member.
  5. ccGroupMemberBanned: Triggered when the logged-in user bans a group member from the group.
  6. ccGroupMemberKicked: Triggered when the logged-in user kicks another group member from the group.
  7. ccGroupMemberUnbanned: Triggered when the logged-in user unbans a user banned from the group.
  8. ccGroupMemberJoined: Triggered when the logged-in user joins a group.
  9. ccGroupMemberAdded: Triggered when the logged-in user adds new members to the group.
  10. ccOwnershipChanged: Triggered when the logged-in user transfers the ownership of their group to some other member.

To listen to group events

import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart' as sdk;
import 'package:flutter/material.dart';

class GroupEventsExample extends StatefulWidget {
const GroupEventsExample({super.key});


State<GroupEventsExample> createState() => _GroupEventsExampleState();
}

class _GroupEventsExampleState extends State<GroupEventsExample> with CometChatGroupEventListener {
String listenerID = "unique_listener_ID";


void initState() {
super.initState();

CometChatGroupEvents.addGroupsListener(listenerID, this); // Add the listener
}


void dispose() {
super.dispose();

CometChatGroupEvents.removeGroupsListener(listenerID); // Remove the listener
}


void ccGroupCreated(Group group) {
// TODO("Not yet implemented")
}


void ccGroupDeleted(Group group) {
// TODO("Not yet implemented")
}


void ccGroupLeft(sdk.Action message, User leftUser, Group leftGroup) {
// TODO("Not yet implemented")
}


void ccGroupMemberScopeChanged(sdk.Action message, User updatedUser, String scopeChangedTo, String scopeChangedFrom, Group group) {
// TODO("Not yet implemented")
}


void ccGroupMemberBanned(sdk.Action message, User bannedUser, User bannedBy, Group bannedFrom) {
// TODO("Not yet implemented")
}


void ccGroupMemberKicked(sdk.Action message, User kickedUser, User kickedBy, Group kickedFrom) {
// TODO("Not yet implemented")
}


void ccGroupMemberUnbanned(sdk.Action message, User unbannedUser, User unbannedBy, Group unbannedFrom) {
// TODO("Not yet implemented")
}


void ccGroupMemberJoined(User joinedUser, Group joinedGroup) {
// TODO("Not yet implemented")
}


void ccGroupMemberAdded(List<sdk.Action> messages, List<User> usersAdded, Group groupAddedIn, User addedBy) {
// TODO("Not yet implemented")
}


void ccOwnershipChanged(Group group, GroupMember newOwner) {

}


Widget build(BuildContext context) {
return const Placeholder();
}

}

Conversation Events

The CometChatConversationEvents component emits events when the logged-in user performs actions related to conversations. This allows for the UI to be updated accordingly. Below are the events emitted by the Conversation Component:

  1. ccConversationDeleted: Triggered when the logged-in user deletes a conversation.

To listen to conversation events and handle them in your application, you can use the following code snippets:

import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';

class ConversationEventsExample extends StatefulWidget {
const ConversationEventsExample({super.key});


State<ConversationEventsExample> createState() => _ConversationEventsExampleState();
}

class _ConversationEventsExampleState extends State<ConversationEventsExample> with CometChatConversationEventListener {
String listenerID = "unique_listener_ID";


void initState() {
super.initState();

CometChatConversationEvents.addConversationListListener(listenerID, this); // Add the listener
}


void dispose() {
super.dispose();

CometChatConversationEvents.removeConversationListListener(listenerID); // Remove the listener
}


void ccConversationDeleted(Conversation conversation) {
// TODO("Not yet implemented")
}


Widget build(BuildContext context) {
return const Placeholder();
}

}

Message Events

CometChatMessageEvents emits events when various actions are performed on messages within the application. These events facilitate updating the UI accordingly. Below are the events emitted by the MessageEvents component:

  1. ccMessageSent: Triggered whenever a logged-in user sends any message. It can have two states: inProgress and sent.
  2. ccMessageEdited: Triggered whenever a logged-in user edits any message from the list of messages. It can have two states: inProgress and sent.
  3. ccMessageDeleted: Triggered whenever a logged-in user deletes any message from the list of messages.
  4. ccMessageRead: Triggered whenever a logged-in user reads any message.
  5. ccLiveReaction: Triggered whenever a logged-in user clicks on a live reaction.
  6. ccMessageForwarded: Triggered whenever a logged-in user forwards any message to a list of users or groups. It can have a state of status.
  7. onTextMessageReceived: Triggered when a text message is received.
  8. onMediaMessageReceived: Triggered when a media message is received.
  9. onCustomMessageReceived: Triggered when a custom message is received.
  10. onTypingStarted: Triggered when a typing indicator starts.
  11. onTypingEnded: Triggered when a typing indicator ends.
  12. onMessagesDelivered: Triggered when messages are delivered.
  13. onMessagesRead: Triggered when messages are read.
  14. onMessageEdited: Triggered when a message is edited.
  15. onMessageDeleted: Triggered when a message is deleted.
  16. onTransientMessageReceived: Triggered when a transient message is received.
  17. onFormMessageReceived: Triggered when a form message is received.
  18. onCardMessageReceived: Triggered when a card message is received.
  19. onCustomInteractiveMessageReceived: Triggered when a custom interactive message is received.
  20. onInteractionGoalCompleted: Triggered when an interaction goal is completed.
  21. onSchedulerMessageReceived: Triggered when a scheduler message is received.
  22. onMessageReactionAdded: Triggered when a reaction is added to a message.
  23. onMessageReactionRemoved: Triggered when a reaction is removed from a message.

To listen to message events and handle them in your application, you can use the following code snippets:

import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';

class MessageEventsExample extends StatefulWidget {
const MessageEventsExample({super.key});


State<MessageEventsExample> createState() => _MessageEventsExampleState();
}

class _MessageEventsExampleState extends State<MessageEventsExample> with CometChatMessageEventListener {
String listenerID = "unique_listener_ID";


void initState() {
super.initState();

CometChatMessageEvents.addMessagesListener(listenerID, this); // Add the listener
}


void dispose() {
super.dispose();

CometChatConversationEvents.removeConversationListListener(listenerID); // Remove the listener
}


void ccMessageSent(BaseMessage message, MessageStatus messageStatus) {
// TODO("Not yet implemented")
}


void ccMessageEdited(BaseMessage message, MessageEditStatus status) {
// TODO("Not yet implemented")
}


void ccMessageDeleted(BaseMessage message, EventStatus messageStatus) {
// TODO("Not yet implemented")
}


void ccMessageRead(BaseMessage message) {
// TODO("Not yet implemented")
}


void ccLiveReaction(String reaction) {
// TODO("Not yet implemented")
}


void onTextMessageReceived(TextMessage textMessage) {
// TODO("Not yet implemented")
}


void onMediaMessageReceived(MediaMessage mediaMessage) {
// TODO("Not yet implemented")
}


void onCustomMessageReceived(CustomMessage customMessage) {
// TODO("Not yet implemented")
}


void onTypingStarted(TypingIndicator typingIndicator) {
// TODO("Not yet implemented")
}


void onTypingEnded(TypingIndicator typingIndicator) {
// TODO("Not yet implemented")
}


void onMessagesDelivered(MessageReceipt messageReceipt) {
// TODO("Not yet implemented")
}


void onMessagesRead(MessageReceipt messageReceipt) {
// TODO("Not yet implemented")
}


void onMessageEdited(BaseMessage message) {
// TODO("Not yet implemented")
}


void onMessageDeleted(BaseMessage message) {
// TODO("Not yet implemented")
}


void onTransientMessageReceived(TransientMessage message) {
// TODO("Not yet implemented")
}


void onFormMessageReceived(FormMessage formMessage) {
// TODO("Not yet implemented")
}


void onCardMessageReceived(CardMessage cardMessage) {
// TODO("Not yet implemented")
}


void onCustomInteractiveMessageReceived(
CustomInteractiveMessage customInteractiveMessage) {
// TODO("Not yet implemented")
}


void onInteractionGoalCompleted(InteractionReceipt receipt) {
// TODO("Not yet implemented")
}


void onSchedulerMessageReceived(SchedulerMessage schedulerMessage) {
// TODO("Not yet implemented")
}


void onMessageReactionAdded(ReactionEvent reactionEvent) {
// TODO("Not yet implemented")
}


void onMessageReactionRemoved(ReactionEvent reactionEvent) {
// TODO("Not yet implemented")
}


Widget build(BuildContext context) {
return const Placeholder();
}
}

Call Events

CometChatCallEvents emits events related to calls within the application. This class provides methods to listen to call-related events and handle them accordingly.

  1. ccOutgoingCall: Triggered when the logged-in user initiates an outgoing call.
  2. ccCallAccepted: Triggered when a call is accepted.
  3. ccCallRejected: Triggered when a call is rejected.
  4. ccCallEnded: Triggered when a call is ended.
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';

class CallEventsExample extends StatefulWidget {
const CallEventsExample({super.key});


State<CallEventsExample> createState() => _CallEventsExampleState();
}

class _CallEventsExampleState extends State<CallEventsExample> with CometChatCallEventListener {
String listenerID = "unique_listener_ID";


void initState() {
super.initState();

CometChatCallEvents.addCallEventsListener(listenerID, this); // Add the listener
}


void dispose() {
super.dispose();

CometChatCallEvents.removeCallEventsListener(listenerID); // Remove the listener
}


void ccOutgoingCall(Call call) {
// TODO("Not yet implemented")
}


void ccCallAccepted(Call call) {
// TODO("Not yet implemented")
}


void ccCallRejected(Call call) {
// TODO("Not yet implemented")
}


void ccCallEnded(Call call) {
// TODO("Not yet implemented")
}


Widget build(BuildContext context) {
return const Placeholder();
}
}

UI Events

CometChatUIEvents emits events related to UI components within the CometChat UI. This class provides methods to listen to UI-related events and handle them accordingly.

Following are the UI events

  1. showPanel: Triggered to show an additional UI panel with custom elements.
  2. hidePanel: Triggered to hide a previously shown UI panel.
  3. ccActiveChatChanged: Triggered when the active chat changes, providing information about the current message, user, and group.
  4. ccOpenChat: Triggered to open a chat with a specific user or group.

To listen to UI events and handle them in your application, you can use the following code snippet:

import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';

class UIEventsExample extends StatefulWidget {
const UIEventsExample({super.key});


State<UIEventsExample> createState() => _UIEventsExampleState();
}

class _UIEventsExampleState extends State<UIEventsExample> with CometChatUIEventListener {
String listenerID = "unique_listener_ID";


void initState() {
super.initState();

CometChatUIEvents.addUiListener(listenerID, this); // Add the listener
}


void dispose() {
super.dispose();

CometChatUIEvents.removeUiListener(listenerID); // Remove the listener
}


void showPanel(Map<String, dynamic>? id, CustomUIPosition uiPosition, WidgetBuilder child) {
// TODO("Not yet implemented")
}


void hidePanel(Map<String, dynamic>? id, CustomUIPosition uiPosition) {
// TODO("Not yet implemented")
}


void ccActiveChatChanged(Map<String, dynamic>? id, BaseMessage? lastMessage, User? user, Group? group, int unreadMessageCount) {
// TODO("Not yet implemented")
}


void openChat(User? user, Group? group) {
// TODO("Not yet implemented")
}


void ccComposeMessage(String text, MessageEditStatus status) {
// TODO("Not yet implemented")
}


void onAiFeatureTapped(User? user, Group? group) {
// TODO("Not yet implemented")
}


Widget build(BuildContext context) {
return const Placeholder();
}
}