Skip to main content
Quick Reference for AI Agents & Developers
  • Add reaction: CometChat.addReaction(messageId:reaction:onSuccess:onError:)
  • Remove reaction: CometChat.removeReaction(messageId:reaction:onSuccess:onError:)
  • Fetch reactions: ReactionsRequestBuilder().setMessageId(messageId:).build()fetchNext(onSuccess:onError:)
  • Listen for reactions: onMessageReactionAdded(_:), onMessageReactionRemoved(_:) in message listener
  • Related: Send Message · Messaging Overview
Enhance user engagement in your chat application with message reactions. Users can express their emotions using reactions to messages. This feature allows users to add or remove reactions, and to fetch all reactions on a message.

Add a Reaction

Users can add a reaction to a message by calling addReaction with the message ID and the reaction emoji.
Method: CometChat.addReaction(messageId:reaction:)
Request:Updated Reactions List:
You can react on Text, Media and Custom messages.

Remove a Reaction

Removing a reaction from a message can be done using the removeReaction method.
Method: CometChat.removeReaction(messageId:reaction:)

Fetch Reactions for a Message

To get all reactions for a specific message, create a ReactionsRequest using ReactionsRequestBuilder.

Fetch Next Reactions

Method: ReactionsRequest.fetchNext()

Fetch Reactions for Specific Emoji

Fetch Previous Reactions


Real-time Reaction Events

Keep the chat interactive with real-time updates for reactions.
Method: onMessageReactionAdded(reactionEvent: ReactionEvent)ReactionEvent Object:

Get Reactions List

To retrieve the list of reactions on a particular message:

Check if Logged-in User Has Reacted


Update Message With Reaction Info

When you receive a real-time reaction event, use this method to update the message with the latest reaction information. This keeps your local message state in sync with the server.

Method Signature

Parameters

ReactionAction Enum Values

Usage Example - Reaction Added

Usage Example - Reaction Removed

Complete Real-Time Handling Example

The method returns a BaseMessage with updated reactions array:Each ReactionCount contains:
Notes:
  • This is a synchronous method - no callbacks needed
  • Always use this method to keep local message state in sync
  • The returned message has updated reactions array
  • Works with both user and group messages
  • Handle both REACTION_ADDED and REACTION_REMOVED events

ReactionCount Object Properties


MessageReaction Object Properties


ReactionEvent Object Properties


Common Error Codes