Message Reaction

Reaction Description

Name

Data Type

Description

Attributes

referenceId

String

ID of a document

referenceType

String

Type of document

reactionName

String

Name of the reaction

'like', 'love' , 'wow'

reactionId

String

ID of the reaction

reactorId

String

ID of the reactor

reactorDisplayName

String

Display name of the reactor

createdAt

Date

The date/time when a reaction is created

Reaction Query

To query for a list of all reactions on the specific message in a channel, right now to get the list of reactions is controlled by AmityReactionRepository. We can observe in the same way as observing message. The only difference is sending postId as the parameter. The operation will return an instance AmityCollection of AmityReaction that contains reaction name, message id, reactor id and reactor display name of the user and the reaction used.

let reactionRepository = AmityReactionRepository(client: client)
var token: AmityNotificationToken?

...

func queryReactions(from message: AmityMessage) {
    let reactionsCollection = reactionRepository.getReactions(message.messageId,
    referenceType: .message, reactionName: nil)
    token = reactionsCollection.observe { collection, change, error in
        for reaction in collection.allObjects() {
            // For example, to handle each reaction in the list.
        }
    }
}

This method will return a LiveObject of all the reactions of a specific message in the specified channel. You can observe the LiveObject in order to update your view whenever you receive a new reaction on that message.

Add Reaction

For adding a new reaction, we can use AmityReactionRepository to perform its operation. Initialize the reactor with the client, don't forget to specify the reaction name as well.

let reactionRepository = AmityReactionRepository(client: client)

...

func addReaction(to message: AmityMessage) {
    // Specify a reaction name for example, "like", "love" and "smile".
    reactionRepository.addReaction("like", referenceId: message.messageId, referenceType: .message) { (success,
    error) in
        // Handle success and error.
    }
}

Remove Reaction

For removing a new reaction, we can use AmityReactionRepository to perform its operation. Initialize the reactor with the client and specify the reaction name.

let reactionRepository = AmityReactionRepository(client: client)

...

func removeReactions(from message: AmityMessage) {
    // Specify a reaction name for example, "like", "love" and "smile".
    reactionRepository.removeReaction("like", referenceId: message.messageId, referenceType: .message) {
    (success, error) in
        // Handle success and error.
    }
}

Last updated