> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-013b37f0.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 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 emits events when the logged-in user executes some action on another user

It contains the following properties and methods

### observer

This is a List of Dictionary that contains components listening to user events in key value pairs

### Type

`[String: CometChatUserEventListener]()`

***

### addListener

this method stores the passed listenerClass against the passed id in the usersListener.

### Signature

### Uses

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    addListener(_ id: String,_ observer: CometChatUserEventListener)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    removeListener(_ id: String)
    ```
  </Tab>
</Tabs>

### 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 user

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onUserBlock(user: User)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onUserUnblock(user: User)
    ```
  </Tab>
</Tabs>

### 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.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    //pass the [User] object of the user which has been blocked by the logged in user
     CometChatUserEvents.emitOnUserBlock(user: User)

    //pass the [User] object of the user which has been unblocked by the logged in user
     CometChatUserEvents.emitOnUserUnblock(user: User)
    ```
  </Tab>
</Tabs>

***

### 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 |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // View controller from your project where you want to listen events.
    public class ViewController: UIViewController {

       public override func viewDidLoad() {
            super.viewDidLoad()

           // Subscribing for the listener to listen events from user module
             CometChatUserEvents.addListener("UNIQUE_ID", self as CometChatUserEventListener)
        }

        public override func viewWillDisappear(_ animated: Bool) {
           // Uncubscribing for the listener to listen events from user module
            CometChatUserEvents.removeListener("LISTENER_ID_USED_FOR_ADDING_THIS_LISTENER")
        }


    }

     // Listener events from user module
    extension  ViewController: CometChatUserEventListener {

        func onUserBlock(user: User) {
            // Do Stuff
        }

        func onUserUnblock(user: User) {
            // Do Stuff
        }
    }
    ```
  </Tab>
</Tabs>

## 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 pairs

### Type

`[String: CometChatGroupEventListener]()`

***

### addListener

this method stores the passed listenerClass against the passed listenerId in the observer.

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    addListener(_ id: String,_ observer: CometChatGroupEventListener)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    removeListener(_ id: String)
    ```
  </Tab>
</Tabs>

### 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 group

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onGroupCreate(group: Group)
    ```
  </Tab>
</Tabs>

### 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 button

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onCreateGroupClick()
    ```
  </Tab>
</Tabs>

***

### onGroupDelete

This method is used to perform some task when the logged-in user has deleted a group.

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onGroupDelete(group: Group)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onGroupMemberLeave(leftUser: User, leftGroup:  Group)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onGroupMemberChangeScope(updatedBy: User , updatedUser: User , scopeChangedTo: CometChat.MemberScope , scopeChangedFrom: CometChat.MemberScope, group: Group)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onGroupMemberBan(bannedUser: User, bannedGroup:  Group, bannedBy: User)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onGroupMemberKick(kickedUser: User, kickedGroup:  Group, kickedBy: User)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onGroupMemberUnban(unbannedUserUser: User, unbannedUserGroup:  Group, unbannedBy: User)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onGroupMemberJoin(joinedUser: User, joinedGroup:  Group)
    ```
  </Tab>
</Tabs>

### 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 group

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onGroupMemberAdd(group: Group, members: [GroupMember], addedBy: User)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onOwnershipChange(group: Group?, member: GroupMember?)
    ```
  </Tab>
</Tabs>

### 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.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    //you need to pass the [Group] object of the group which is created
    CometChatGroupEvents.emitOnGroupCreate(group: Group)

    //you need to pass the [Group] object of the group which is deleted
    CometChatGroupEvents.emitOnGroupDelete(group: Group)

    //emit this when logged in user leaves the group.
    CometChatGroupEvents.emitOnGroupMemberLeave(leftUser: User, leftGroup:  Group)

    //emit this when group member's scope is changed by logged in user.
    CometChatGroupEvents.emitOnGroupMemberChangeScope(updatedBy: User , updatedUser: User , scopeChangedTo: CometChat.MemberScope , scopeChangedFrom: CometChat.MemberScope, group: Group)

    //emit this when group member is banned from the group by logged in user.
    CometChatGroupEvents.emitOnGroupMemberBan(bannedUser: User, bannedGroup:  Group, bannedBy: User)

    //emit this when group member is kicked from the group by logged in user.
    CometChatGroupEvents.emitOnGroupMemberKick(kickedUser: User, kickedGroup:  Group, kickedBy: User)

    //emit this when a banned group member is unbanned from group by logged in user.
    CometChatGroupEvents.emitOnGroupMemberUnban(unbannedUserUser: User, unbannedUserGroup:  Group, unbannedBy: User)

    //emit this when logged in user has joined a group successfully.
    CometChatGroupEvents.emitOnGroupMemberJoin(joinedUser: User, joinedGroup:  Group)

    //emit this when members are added to a group by the logged in user.
    CometChatGroupEvents.emitOnGroupMemberAdd(group: Group, members: [GroupMember], addedBy: User)

    //emit this when ownership is changed by logged in user.
    CometChatGroupEvents.emitOnGroupMemberChangeScope(updatedBy: User , updatedUser: User , scopeChangedTo: CometChat.MemberScope , scopeChangedFrom: CometChat.MemberScope, group: Group)
    ```
  </Tab>
</Tabs>

***

### 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 |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // View controller from your project where you want to listen events.
    public class ViewController: UIViewController {

       public override func viewDidLoad() {
            super.viewDidLoad()

           // Subscribing for the listener to listen events from user module
             CometChatGroupEvents.addListener("UNIQUE_ID", self as CometChatGroupEventListener)
        }

        public override func viewWillDisappear(_ animated: Bool) {
           // Uncubscribing for the listener to listen events from user module
            CometChatGroupEvents.removeListener("LISTENER_ID_USED_FOR_ADDING_THIS_LISTENER")
        }


    }

     // Listener events from groups module
    extension  ViewController: CometChatGroupEventListener {

        public func onGroupMemberAdd(group: Group, members: [GroupMember], addedBy: User) {
            // Do Stuff
        }

        public func onCreateGroupClick() {
             // Do Stuff
        }

        public func onGroupCreate(group: Group) {
            // Do Stuff
        }

        public func onGroupDelete(group: Group) {
            // Do Stuff
        }

        public func onGroupMemberJoin(joinedUser: User, joinedGroup: Group) {
            // Do Stuff
        }

        public func onGroupMemberLeave(leftUser: User, leftGroup: Group) {
            // Do Stuff
        }

        public func onGroupMemberBan(bannedUser: User, bannedGroup: Group) {
             // Do Stuff
        }

        public func onGroupMemberUnban(unbannedUserUser: User, unbannedUserGroup: Group) {
             // Do Stuff
        }

        public func onGroupMemberKick(kickedUser: User, kickedGroup: Group) {
             // Do Stuff
        }

        public func onGroupMemberChangeScope(updatedBy: User, updatedUser: User, scopeChangedTo: CometChat.MemberScope, scopeChangedFrom: CometChat.MemberScope, group: Group) {
              // Do Stuff
        }

        public func onOwnershipChange(group: Group?, member: GroupMember?) {
            // Do Stuff
        }
    }
    ```
  </Tab>
</Tabs>

## Conversation Events

CometChatConversationEvents emits events when the logged-in user executes some action on a conversation object

It contains the following properties and methods

### observer

This is a List of Dictionary that contains components listening to user events in key value pairs

### Type

`[String: CometChatConversationEventListener]()`

***

### addListener

this method stores the passed listenerClass against the passed listenerId in the observer.

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    addListener(_ id: String, _ observer: CometChatConversationEventListener)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    removeListener(_ id: String)
    ```
  </Tab>
</Tabs>

### 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 conversation

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onConversationDelete(conversation: Conversation)
    ```
  </Tab>
</Tabs>

### 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.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    //pass the conversation object you want to delete
    CometChatConversationEvents.emitConversationDelete(conversation: Conversation)
    ```
  </Tab>
</Tabs>

***

### 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 |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // View controller from your project where you want to listen events.
    public class ViewController: UIViewController {

       public override func viewDidLoad() {
            super.viewDidLoad()

           // Subscribing for the listener to listen events from conversation module
             CometChatConversationEvents.addListener("UNIQUE_ID", self as CometChatConversationEventListener)
        }

        public override func viewWillDisappear(_ animated: Bool) {
           // Uncubscribing for the listener to listen events from conversation module
            CometChatConversationEvents.removeListener("LISTENER_ID_USED_FOR_ADDING_THIS_LISTENER")
        }


    }

     // Listener events from conversation module
    extension  ViewController: CometChatConversationEventListener {

        func onConversationDelete(conversation: Conversation) {
            // Do Stuff
        }

    }
    ```
  </Tab>
</Tabs>

## 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 pairs

### Type

`[String: CometChatMessageEventListener]()`

***

### addListener

this method stores the passed listenerClass against the passed id in the observer.

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    addListener(_ id: String,_ observer: CometChatMessageEventListener)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    removeListener(_ id: String)
    ```
  </Tab>
</Tabs>

### 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 message

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onMessageSent(message: BaseMessage, status: MessageStatus)
    ```
  </Tab>
</Tabs>

### 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 message

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onMessageEdit(message: BaseMessage, status: MessageStatus)
    ```
  </Tab>
</Tabs>

### 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 message

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onMessageDelete(message: BaseMessage)
    ```
  </Tab>
</Tabs>

### 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 message

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onMessageRead(message: BaseMessage)
    ```
  </Tab>
</Tabs>

### 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 message

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onLiveReaction(reaction: TransientMessage)
    ```
  </Tab>
</Tabs>

### 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onViewInformation(group: Group)
    ```
  </Tab>
</Tabs>

| 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onParentMessageUpdate(message: BaseMessage)
    ```
  </Tab>
</Tabs>

| 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.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    //emit this when the logged in user has sent a message. Pass the object of the [TextMessage], [MediaMessage] or [CustomMessage] being sent and the [MessageStatus] if [inProgress], [sent] successfully or failed with [error]*_
    CometChatMessageEvents.emitOnMessageSent(message: BaseMessage, status: MessageStatus)

    //emit this for when a message is edited by logged-in user. Pass the object of the [TextMessage], [MediaMessage] or [CustomMessage] being edited and the [MessageEditStatus] if [inProgress] or [success]*_
    CometChatMessageEvents.emitOnMessageEdit(message: BaseMessage, status: MessageStatus)

    //emit this when a message is being deleted by logged-in user. Pass the object of the [TextMessage], [MediaMessage] or [CustomMessage] being deleted and also pass the [EventStatus] if [inProgress] or [success]*_
    CometChatMessageEvents.emitOnMessageDelete(message: BaseMessage)

    //emit this when a message is read by logged-in user. Pass the object of the [TextMessage], [MediaMessage] or [CustomMessage] being read*_
    CometChatMessageEvents.emitOnMessageRead(message: BaseMessage)

    //emit this when a transient message is sent by logged-in user. Pass a [String] asset image of the Live Reaction to show in the animation*_
    CometChatMessageEvents.emitOnLiveReaction(reaction: TransientMessage)

    //emit this when the logged in user clicked on detail icon.*_
    CometChatMessageEvents.emitOnViewInformation(user: User)

    //emit this when the logged in user updates a message that contains replies.*_
    CometChatMessageEvents.emitOnParentMessageUpdate(message: BaseMessage)
    ```
  </Tab>
</Tabs>

***

### 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.                                                        |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // View controller from your project where you want to listen events.
    public class ViewController: UIViewController {

       public override func viewDidLoad() {
            super.viewDidLoad()

           // Subscribing for the listener to listen events from message module
            CometChatMessageEvents.addListener("UNIQUE_ID", self as CometChatMessageEventListener)
        }

        public override func viewWillDisappear(_ animated: Bool) {
           // Uncubscribing for the listener to listen events from message module
            CometChatMessageEvents.removeListener("LISTENER_ID_USED_FOR_ADDING_THIS_LISTENER")
        }


    }

     // Listener events from message module
    extension  ViewController: CometChatMessageEventListener {

         func onMessageSent(message: BaseMessage, status: MessageStatus) {
            // Do Stuff
        }

        func onMessageEdit(message: BaseMessage, status: MessageStatus) {
            // Do Stuff
        }

        func onMessageDelete(message: BaseMessage, status: MessageStatus) {
            // Do Stuff
        }

        func onMessageReply(message: BaseMessage, status: MessageStatus) {
            // Do Stuff
        }

        func onMessageRead(message: BaseMessage) {
             // Do Stuff
        }

        func onLiveReaction(reaction: TransientMessage) {
            // Do Stuff
        }

        func onMessageError(error: CometChatException) {
            // Do Stuff
        }

        func onVoiceCall(user: User) {
           // Do Stuff
        }

        func onVoiceCall(group: Group) {
            // Do Stuff
        }

        func onVideoCall(user: User) {
            // Do Stuff
        }

        func onVideoCall(group: Group) {
             // Do Stuff
        }

        func onViewInformation(user: User) {
            // Do Stuff
        }

        func onMessageReact(message: BaseMessage, reaction: CometChatMessageReaction) {
            // Do Stuff
        }

    }
    ```
  </Tab>
</Tabs>

## 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 pairs

### Type

`[String:`CometChatCallEventListener]\()

***

### addListener

This method stores the passed listenerClass against the passed id in the addListener.

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    addListener(_ id: String,_ observer: CometChatCallEventListener)
    ```
  </Tab>
</Tabs>

| 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    removeListener(_ id: String)
    ```
  </Tab>
</Tabs>

| 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 call

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onIncomingCallAccepted(call: Call)
    ```
  </Tab>
</Tabs>

| 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 call

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onIncomingCallRejected(call: Call)
    ```
  </Tab>
</Tabs>

| 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 call

### Signature

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onCallInitiated(call: Call)
    ```
  </Tab>
</Tabs>

| 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onCallEnded(call: Call)
    ```
  </Tab>
</Tabs>

| 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onOutgoingCallAccepted(call: Call)
    ```
  </Tab>
</Tabs>

| 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

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    onOutgoingCallRejected(call: Call)
    ```
  </Tab>
</Tabs>

| 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.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    //emit this when logged in user initiates a call
    CometChatCallEvents.emitOnCallInitiated(call: Call)

    //emit this when logged in user cancels a call
    CometChatCallEvents.emitOnCallEnded(call: Call)

    //emit this when logged in user accepts the incoming call
    CometChatCallEvents.emitOnIncomingCallAccepted(call: Call)

    //emit this when logged in user rejects the incoming call
    CometChatCallEvents.emitOnIncomingCallRejected(call: Call)
    //emit this when the other user accepts the call
    CometChatCallEvents.emitOnOutgoingCallAccepted(call: Call)

    //emit this when the other user rejects a call
    CometChatCallEvents.emitOnOutgoingCallRejected(call: Call)
    ```
  </Tab>
</Tabs>

### 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 |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // View controller from your project where you want to listen events.
    public class ViewController: UIViewController {

       public override func viewDidLoad() {
            super.viewDidLoad()

           // Subscribing for the listener to listen events from user module
             CometChatCallEvents.addListener("UNIQUE_ID", self as CometChatCallEventListener)
        }

        public override func viewWillDisappear(_ animated: Bool) {
           // Uncubscribing for the listener to listen events from user module
            CometChatCallEvents.removeListener("LISTENER_ID_USED_FOR_ADDING_THIS_LISTENER")
        }


    }

     // Listener events from user module
    extension  ViewController: CometChatCallEventListener {

        func onIncomingCallAccepted(call: Call) {
            // Do Stuff
        }

        func onIncomingCallRejected(call: Call)
            // Do Stuff
        }

        func onCallEnded(call: Call) {
            // Do Stuff
        }

        func onCallInitiated(call: Call)
            // Do Stuff
        }

        func onOutgoingCallAccepted(call: Call) {
            // Do Stuff
        }

        func onOutgoingCallRejected(call: Call)
            // Do Stuff
        }
    }
    ```
  </Tab>
</Tabs>
