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 emits events when the logged-in user executes some action on another user It contains the following properties and methodsobserver
This is a List of Dictionary that contains components listening to user events in key value pairsType
[String: CometChatUserEventListener]()
addListener
this method stores the passed listenerClass against the passed id in the usersListener.Signature
Uses
Parameters
Parameters | Type | Description |
---|---|---|
id | String | the key to store the component against |
observer | CometChatUserEventListener | the component listening to user events |
removeListener
this method removes the entry with the passed id from the usersListener.Signature
Parameters
Parameters | Type | Description |
---|---|---|
id | String | the key of the entry to remove |
onUserBlock
This method is used to perform some task when the logged-in user has blocked a userSignature
Parameters
Parameters | Type | Description |
---|---|---|
user | User | the user that has been blocked |
onUserUnblock
This method is used to perform some task when the logged-in user has unblocked a blocked user.Signature
Parameters
Parameters | Type | Description |
---|---|---|
user | User | the user that has been unblocked |
Return Type
void
Emitting User Events
There are two types of user event listeners, one is for the SDK, which listens for events emitted from the backend for actions taken by users other than the logged in user and second, the events specific to the UI Kit which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contains how to emit such client-side user events to inform other UI components in your project that a user has been blocked or unblocked, the methods being used are static and hence they can be called without having to create an instance of CometChatUserEvents class.Listening to User Events
Here we will go through how anyone can listen to these client-side User Events to update the state of the UI accordingly.Events | Description |
---|---|
onUserBlocked | This will get triggered when the logged in user blocks another user |
onUserUnblocked | This will get triggered when the logged in user unblocks another user |
Group Events
CometChatGroupEvents emits events when the logged-in user executes some action on a group or group member It contains the following properties and methods:observer
This is a List of Dictionary that contains components listening to group events in key value pairsType
[String: CometChatGroupEventListener]()
addListener
this method stores the passed listenerClass against the passed listenerId in the observer.Signature
Parameters
Parameters | Type | Description |
---|---|---|
id | String | the key to store the component against |
observer | CometChatGroupEventListener | the component listening to group events |
removeListener
this method removes the entry with the passed listenerId from the observer.Signature
Parameters
Parameters | Type | Description |
---|---|---|
id | String | the key of the entry to remove |
onGroupCreate
This method is used to perform some task when the logged-in user has created a groupSignature
Parameters
Parameters | Type | Description |
---|---|---|
group | Group | the new group that has been created |
onCreateGroupClick
This method is used to perform some task when the logged-in user click on Create group buttonSignature
onGroupDelete
This method is used to perform some task when the logged-in user has deleted a group.Signature
Parameters
Parameters | Type | Description |
---|---|---|
group | Group | the group that has been deleted |
onGroupMemberLeave
This method is used to perform some task when the logged-in user has left a group.Signature
Parameters
Parameters | Type | Description |
---|---|---|
leftUser | User | the user that has left the group |
leftGroup | Group | the group from which the logged-user has left |
onGroupMemberChangeScope
This method is used to perform some task when the logged-in user has changed the scope of a member of a group.Signature
Parameters
Parameters | Type | Description |
---|---|---|
updatedBy | User | the user who changed the scope of group member |
updatedUser | User | the user whose scope has been changed |
scopeChangedTo | String | the new scope |
scopeChangedFrom | String | the old scope |
group | Group | the group from where the scope change has occurred |
onGroupMemberBan
This method is used to perform some task when the logged-in user has banned a user from the group.Signature
Parameters
Parameters | Type | Description |
---|---|---|
bannedUser | User | the user that has been banned |
bannedBy | User | the user who has banned |
bannedFrom | Group | the group from which the user has been banned |
onGroupMemberKick
This method is used to perform some task when the logged-in user has kicked a user from the group.Signature
Parameters
Parameters | Type | Description |
---|---|---|
kickedUser | User | the banned user that has been kicked |
kickedBy | User | the user who has kicked |
kickedGroup | Group | the group from which the user has been kicked |
onGroupMemberUnban
This method is used to perform some task when the logged-in user has unbanned a banned user from a group.Signature
Parameters
Parameters | Type | Description |
---|---|---|
unbannedUser | User | the banned user that has been unbanned |
unbannedBy | User | the user who has unbanned |
unbannedFrom | Group | the group from which the banned user has been unbanned |
onGroupMemberJoin
This method is used to perform some task when the logged-in user has joined a group.Signature
Parameters
Parameters | Type | Description |
---|---|---|
joinedUser | User | the user that has been unblocked |
joinedGroup | Group | the group the users have been added to |
onGroupMemberAdd
This method is used to perform some task when the logged-in user has added new members to the groupSignature
Parameters
Parameters | Type | Description |
---|---|---|
members | List<User> | the list of users added |
group | Group | the group the users have been added to |
addedBy | User | the user who has added those new members |
onOwnershipChange
This method is used to perform some task when the logged-in user has transferred their ownership of a group.Signature
Parameters
Parameters | Type | Description |
---|---|---|
group | Group | the group where the ownership has been changed |
member | GroupMember | the group member who has been made owner of the group |
Emitting Group Events
There are two types of group event listeners, one is for the SDK, which listens for events emitted from the backend for actions taken by users other than the logged in user and second, the events specific to the UI Kit which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contains how to emit such client-side group events to inform other UI components in a project that a group has been created or deleted or new members have been added to the group, the logged in user themselves have joined a group, members being banned by the logged in user or the change of ownership or scope of a group member, the methods being used are static and hence they can be called without having to create an instance of CometChatGroupEvents class.Listening to Group Events
Here we will go through how anyone can listen to these client-side Group Events to update the state of the UI accordingly.Events | Description |
---|---|
onGroupCreate | This will get triggered when the logged in user creates a group |
onGroupDelete | This will get triggered when the logged in user deletes a group |
onGroupMemberLeave | This will get triggered when the logged in user leaves a group |
onGroupMemberChangeScope | This will get triggered when the logged in user changes the scope of another group member |
onGroupMemberBan | This will get triggered when the logged in user bans a group member from the group |
onGroupMemberKick | This will get triggered when the logged in user kicks another group member from the group |
onGroupMemberUnban | This will get triggered when the logged in user unbans a user banned from the group |
onGroupMemberJoin | This will get triggered when the logged in user joins a group |
onGroupMemberAdd | This will get triggered when the logged in user add new members to the group |
onOwnershipChange | This will get triggered when the logged in user transfer the ownership of their group to some other member |
Conversation Events
CometChatConversationEvents emits events when the logged-in user executes some action on a conversation object It contains the following properties and methodsobserver
This is a List of Dictionary that contains components listening to user events in key value pairsType
[String: CometChatConversationEventListener]()
addListener
this method stores the passed listenerClass against the passed listenerId in the observer.Signature
Parameters
Parameters | Type | Description |
---|---|---|
id | String | the key to store the component against |
observer | CometChatConversationEvents | the component listening to conversation events |
removeListener
this method removes the entry with the passed id from the observer.Signature
Parameters
Parameters | Type | Description |
---|---|---|
id | String | the key of the entry to remove |
Return Type
void
onConversationDelete
This method is used to perform some task when the logged-in user has deleted a conversationSignature
Parameters
Parameters | Type | Description |
---|---|---|
conversation | Conversation | the user that has been deleted |
Emitting Conversation Events
Here we will go through how to emit events specific to the UI Kit which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contains how to emit such client-side conversation events to inform other UI components in a project that a conversation has been deleted, the methods being used are static and hence they can be called without having to create an instance of CometChatConversationEvents class.Listening to Conversation Events
Here we will go through how anyone can listen to these client-side Conversation Events to update the state of the UI accordingly.Event | Description |
---|---|
onConversationDelete | This event will be triggered when the logged in user deletes a conversation |
Message Events
CometChatMessageEvents emits events when the logged-in user executes some action involving any message object. It contains the following properties and methods:observer
This is a List of Dictionary that contains components listening to message events in key value pairsType
[String: CometChatMessageEventListener]()
addListener
this method stores the passed listenerClass against the passed id in the observer.Signature
Parameters
Parameters | Type | Description |
---|---|---|
id | String | the key to store the component against |
observer | CometChatMessageEventListener | the component listening to message events |
removeListener
this method removes the entry with the passed id from the observer.Signature
Parameters
Parameters | Type | Description |
---|---|---|
id | String | the key of the entry to remove |
onMessageSent
This method is used to perform some task when the logged-in user has sent a messageSignature
Parameters
Parameters | Type | Description |
---|---|---|
message | BaseMessage | the message that has been sent |
messageStatus | MessageStatus | the status of the message, it can be inProgress , sent or error |
onMessageEdit
This method is used to perform some task when the logged-in user has edited a messageSignature
Parameters
Parameters | Type | Description |
---|---|---|
message | BaseMessage | the message that has been sent |
messageStatus | MessageEditStatus | the status of the message, it can be inProgress or success |
onMessageDelete
This method is used to perform some task when the logged-in user has deleted a messageSignature
Parameters
Parameters | Type | Description |
---|---|---|
message | BaseMessage | the message that has been sent |
messageStatus | EventStatus | the status of the message, it can be inProgress or success |
onMessageRead
This method is used to perform some task when the logged-in user has read a messageSignature
Parameters
Parameters | Type | Description |
---|---|---|
message | BaseMessage | the message that has been read |
onLiveReaction
This method is used to perform some task when the logged-in user has a sent a transient messageSignature
Parameters
Parameters | Type | Description |
---|---|---|
reaction | TransientMessage | the image to send as transient message |
onViewInformation
This method is used to perform some task when the logged-in user click on detail button.Signature
Parameters | Type | Description |
---|---|---|
group | Group | the group for which the information has been shown |
onParentMessageUpdate
This method is used to perform some task when the logged-in user updates a message that has replies.Signature
Parameters | Type | Description |
---|---|---|
message | BaseMessage | the message that has been updated |
Emitting Message Events
There are two types of message event listeners, one is for the SDK, which listens for events emitted from the backend for actions taken by users other than the logged in user; and second, the events specific to the UI Kit which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contains how to emit such client-side message events to inform other UI components in a project.Listening to Message Events
Here we will go through how anyone can listen to these client-side Message Events to update the state of the UI accordingly.Events | Description |
---|---|
onMessageSent | Triggers whenever a loggedIn user sends any message, it will have two states such as: inProgress & sent |
onMessageEdit | Triggers whenever a loggedIn user edits any message from the list of messages .it will have two states such as: inProgress & sent |
onMessageDelete | Triggers whenever a loggedIn user deletes any message from the list of messages |
onMessageRead | Triggers whenever a loggedIn user reads any message. |
onLiveReaction | Triggers whenever a loggedIn user clicks on live reaction |
onViewInformation | Triggers whenever a loggedIn user clicks on detail icon |
onParentMessageUpdate | Triggers whenever a loggedIn user updates a message that contains replies. |
Call Events
CometChatCallEvents emits events when the logged-in user executes some action involving any call object. It contains the following properties and methods:observer
This is a List of Dictionary that contains components listening to call events in key value pairsType
[String:
CometChatCallEventListener]()
addListener
This method stores the passed listenerClass against the passed id in the addListener.Signature
Parameters | Type | Description |
---|---|---|
id | String | the key to store the component against |
observer | CometChatCallEventListener | the component listening to call events |
removeListener
This method removes the entry with the passed id from the observer.Signature
Parameter | Type | Description |
---|---|---|
id | String | the key of the entry to remove |
onIncomingCallAccepted
This method is used to perform some task when the logged-in user accepts the incoming callSignature
Parameters | Type | Description |
---|---|---|
call | Call | the call that has been accepted |
onIncomingCallRejected
This method is used to perform some task when the logged-in user rejects the incoming callSignature
Parameters | Type | Description |
---|---|---|
call | Call | the call that has been rejected |
onCallInitiated
This method is used to perform some task when the logged-in user initiates a callSignature
Parameters | Type | Description |
---|---|---|
call | Call | the call that has been initiated |
onCallEnded
This method is used to perform some task when the ongoing or outgoing call ends.Signature
Parameters | Type | Description |
---|---|---|
call | Call | the call that has been ended |
onOutgoingCallAccepted
This method is used to perform some task when the outgoing call is accepted.Signature
Parameters | Type | Description |
---|---|---|
call | Call | the call that has been accepted by the other user. |
onOutgoingCallRejected
This method is used to perform some task when the outgoing call is rejected.Signature
Parameters | Type | Description |
---|---|---|
call | Call | the call that has been rejected by the other user. |
Emitting Call Events
There are two types of call event listeners, one for the SDK, which listens for events emitted from the backend for actions taken by users other than the logged-in user; and another for events specific to the UI Kit, which listens for events emitted from the client side for actions made by the logged-in user. The code snippets shared below contain how to emit such client-side call events to inform other UI components in a project.Listening to Call Events
Here we will go through how anyone can listen to these client-side Call Events to update the state of the UI accordingly.Event | Description |
---|---|
onIncomingCallAccepted | Triggers whenever incoming call is accepted by the user |
onIncomingCallRejected | Triggers whenever incoming call is rejected by the user |
onCallEnded | Triggers whenever the call is ended |
onCallInitiated | Triggers whenever the call is getting initiated |
onOutgoingCallAccepted | Triggers whenever outgoing call is accepted by the user |
onOutgoingCallRejected | Triggers whenever outgoing call is rejected by the user |