Use this file to discover all available pages before exploring further.
AI Integration Quick Reference
// Add a reactionCometChat.addReaction(messageId: 148, reaction: "\u{1F60A}") { msg in } onError: { err in }// Remove a reactionCometChat.removeReaction(messageId: 148, reaction: "\u{1F60A}") { msg in } onError: { err in }// Fetch reactions for a messagelet request = ReactionsRequestBuilder().setMessageId(messageId: 148).setLimit(limit: 10).build()request.fetchNext { reactions in } onError: { error in }// Listen for reaction events (CometChatMessageDelegate)func onMessageReactionAdded(reactionEvent: ReactionEvent) { }func onMessageReactionRemoved(reactionEvent: ReactionEvent) { }
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.
Removing a reaction from a message can be done using the removeReaction method.Both addReaction() and removeReaction() return a BaseMessage object with the updated reactions.
Swift
CometChat.removeReaction(messageId: 148, reaction: "😴") { message in print("Reactions: \(message.getReactions())")} onError: { error in print("Error: \(error?.errorDescription)")}
reactionsRequest.fetchPrevious { reactions in for reaction in reactions { print("Reaction: \(reaction.stringValue())") }} onError: { error in print("Error: \(error?.errorDescription)")}
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.
extension YourViewController: CometChatMessageDelegate { func onMessageReactionAdded(reactionEvent: ReactionEvent) { // Get the message from your local list var message: BaseMessage = getMessageFromList(reactionEvent.reaction.messageId) // Get the reaction from the event let messageReaction: MessageReaction = reactionEvent.reaction // Update the message with new reaction info let modifiedMessage = CometChat.updateMessageWithReactionInfo( baseMessage: message, messageReaction: messageReaction, action: .REACTION_ADDED ) // Update your UI with the modified message updateMessageInList(modifiedMessage) }}
extension YourViewController: CometChatMessageDelegate { func onMessageReactionRemoved(reactionEvent: ReactionEvent) { // Get the message from your local list var message: BaseMessage = getMessageFromList(reactionEvent.reaction.messageId) // Get the reaction from the event let messageReaction: MessageReaction = reactionEvent.reaction // Update the message with removed reaction info let modifiedMessage = CometChat.updateMessageWithReactionInfo( baseMessage: message, messageReaction: messageReaction, action: .REACTION_REMOVED ) // Update your UI with the modified message updateMessageInList(modifiedMessage) }}