Skip to main content

Documentation Index

Fetch the complete documentation index at: https://learn.social.plus/llms.txt

Use this file to discover all available pages before exploring further.

Add & Remove Reactions

Enable users to express emotions and engage with content through comprehensive reaction management. Build expressive communities where users can add, modify, and remove reactions on posts, stories, comments, and messages with real-time synchronization.

Architecture Overview

Key Features

Multi-Content Reactions

Add reactions to posts, stories, comments, and messages

Real-time Updates

Instant reaction synchronization across all clients

Flexible Reaction Types

Support unlimited custom reaction types up to 100 characters

Optimistic Updates

Immediate UI feedback with automatic error handling

Add Reaction

Enable users to express emotions and engagement through reactions. The addReaction function provides comprehensive support for all content types with real-time synchronization and optimistic UI updates.

Parameters

Type: stringRequired: YesDescription: Name of the reaction to add. Case-sensitive with maximum length of 100 characters.Examples: "like", "love", "wow", "celebrate", "support"Validation:
  • Maximum 100 characters
  • Case-sensitive (“like” ≠ “Like”)
  • Alphanumeric and special characters allowed
Type: ReactionReferenceTypeRequired: YesDescription: Specifies the type of content to react to.Valid Values:
  • POST - React to posts in feeds and communities
  • STORY - React to ephemeral story content
  • COMMENT - React to comments in discussions
  • MESSAGE - React to messages in chats
Type: stringRequired: YesDescription: Unique identifier of the content to react to. Must correspond to existing content of the specified reference type.
Type: FunctionRequired: No (varies by platform)Description: Optional callback function to handle success/error responses. Returns reaction data on success.

Implementation

import AmitySDK

class ReactionManager {
    private let reactionRepository: AmityReactionRepository
    
    init(client: Client) {
        self.reactionRepository = AmityReactionRepository(client: client)
    }
    
    func addReaction(
        reactionName: String,
        referenceType: AmityReactionReferenceType,
        referenceId: String,
        completion: @escaping (Result<AmityReaction, Error>) -> Void
    ) {
        reactionRepository.addReaction(
            reactionName,
            referenceType: referenceType,
            referenceId: referenceId
        ) { [weak self] success, error in
            if success {
                print("Reaction '\(reactionName)' added successfully")
                self?.trackReactionAdded(reactionName: reactionName, referenceType: referenceType)
                completion(.success(success))
            } else {
                print("Failed to add reaction: \(error?.localizedDescription ?? "Unknown error")")
                completion(.failure(error ?? ReactionError.unknown))
            }
        }
    }
    
    private func trackReactionAdded(reactionName: String, referenceType: AmityReactionReferenceType) {
        // Analytics tracking
        AnalyticsManager.shared.track("reaction_added", parameters: [
            "reaction_name": reactionName,
            "reference_type": referenceType.rawValue,
            "timestamp": Date().timeIntervalSince1970
        ])
    }
}

Remove Reaction

The removeReaction function allows users to remove a previously added reaction from content. This provides users with greater control over their engagement and allows them to change their minds or update their reactions over time.

Architecture

Features

Instant Removal

Remove reactions immediately with real-time updates

Reference Support

Remove reactions from posts, stories, comments, and messages

Analytics Tracking

Track removal patterns and user engagement metrics

Error Handling

Comprehensive validation and error management

Parameters

Type: stringRequired: YesDescription: The name of the reaction to remove. Names are case-sensitive (e.g., “like” vs “Like” are different reactions).Example: "like", "love", "angry"
Type: ReactionReferenceTypeRequired: YesDescription: Specifies the type of content to remove reaction from.Valid Values:
  • POST - Remove reaction from posts
  • STORY - Remove reaction from story content
  • COMMENT - Remove reaction from comments
  • MESSAGE - Remove reaction from messages
Type: stringRequired: YesDescription: Unique identifier of the content to remove reaction from.

Implementation

import AmitySDK

class ReactionManager {
    private let reactionRepository: AmityReactionRepository
    
    init(client: Client) {
        self.reactionRepository = AmityReactionRepository(client: client)
    }
    
    func removeReaction(
        reactionName: String,
        referenceType: AmityReactionReferenceType,
        referenceId: String,
        completion: @escaping (Result<Bool, Error>) -> Void
    ) {
        reactionRepository.removeReaction(
            reactionName,
            referenceType: referenceType,
            referenceId: referenceId
        ) { [weak self] success, error in
            if success {
                print("Reaction '\(reactionName)' removed successfully")
                self?.trackReactionRemoved(reactionName: reactionName, referenceType: referenceType)
                completion(.success(true))
            } else {
                print("Failed to remove reaction: \(error?.localizedDescription ?? "Unknown error")")
                completion(.failure(error ?? ReactionError.unknown))
            }
        }
    }
    
    private func trackReactionRemoved(reactionName: String, referenceType: AmityReactionReferenceType) {
        AnalyticsManager.shared.track("reaction_removed", parameters: [
            "reaction_name": reactionName,
            "reference_type": referenceType.rawValue,
            "timestamp": Date().timeIntervalSince1970
        ])
    }
}

Best Practices

Optimistic Updates

Update UI immediately while processing the reaction in the background for better user experience.

Error Handling

Always implement proper error handling and provide user feedback for failed operations.

State Management

Maintain local reaction state to prevent duplicate operations and enable offline functionality.

Analytics Tracking

Track reaction patterns to understand user engagement and improve content strategy.

Implementation Guidelines

  • Always validate reaction names and reference IDs before making API calls
  • Implement proper error handling for network failures and invalid requests
  • Provide meaningful error messages to users
  • Use try-catch blocks to handle exceptions gracefully
  • Implement caching to track existing reactions and prevent redundant API calls
  • Use debouncing for rapid add/remove operations
  • Consider implementing offline support with sync when connection is restored
  • Batch multiple reaction operations when possible
  • Provide immediate visual feedback when reactions are added or removed
  • Show loading states during API operations
  • Handle edge cases like network failures gracefully
  • Allow users to undo reaction changes within a reasonable time window
  • Track reaction addition and removal events for engagement analysis
  • Monitor API response times and error rates
  • Log user interaction patterns to improve UX
  • Implement A/B testing for different reaction UI designs

Use Cases

Enable users to react to posts in social feeds with various emotion types like likes, loves, and reactions.Example: A photo-sharing app where users can react to friends’ photos with different emotions.

Error Handling

  • Network Errors: Handle offline scenarios and poor connectivity
  • Validation Errors: Invalid reaction names or reference IDs
  • Permission Errors: User lacks permission to react to content
  • Rate Limiting: Too many reactions added/removed too quickly
{
  "error": {
    "code": "REACTION_NOT_FOUND",
    "message": "The specified reaction does not exist",
    "details": {
      "reactionName": "like",
      "referenceId": "post_123"
    }
  }
}
  • Implement retry logic with exponential backoff
  • Provide fallback UI states for failed operations
  • Cache operations for offline execution when connection is restored
  • Show appropriate error messages based on error type