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.

Query Reactions

Retrieve comprehensive reaction data to analyze user engagement, build analytics dashboards, and understand community sentiment. The getReactions method provides detailed information about reactions across all content types with powerful filtering and pagination capabilities.

Architecture Overview

Key Features

Comprehensive Queries

Query reactions across posts, stories, comments, and messages

Advanced Filtering

Filter by reaction type, user, time range, and custom criteria

Real-time Updates

Live reaction data synchronization and automatic updates

Analytics Ready

Built-in aggregation and analytics for engagement insights

Query Parameters

Type: ReactionReferenceTypeRequired: YesDescription: Specifies the type of content to query reactions for.Valid Values:
  • POST - Query reactions for posts
  • STORY - Query reactions for story content
  • COMMENT - Query reactions for comments
  • MESSAGE - Query reactions for messages
Type: stringRequired: YesDescription: Unique identifier of the content to query reactions for.Example: "post_123", "comment_456"
Type: stringRequired: NoDescription: Optional filter to query only specific reaction types. If omitted, returns all reaction types.Example: "like", "love", "angry"
Type: numberRequired: NoDescription: Maximum number of reactions to return. Default varies by platform.Range: 1-100 (platform dependent)
Type: SortOrderRequired: NoDescription: Sort order for returned reactions.Options: NEWEST_FIRST, OLDEST_FIRST

Reaction Data Model

Each reaction query returns rich data including:
PropertyTypeDescription
reactionIdstringUnique reaction identifier
reactionNamestringType of reaction (e.g., “like”, “love”)
reactorIdstringID of the user who reacted
reactorDisplayNamestringDisplay name of the reactor
createdAtDateTimeWhen the reaction was created
metadataobjectAdditional reaction metadata

Implementation

import AmitySDK

class ReactionQueryManager {
    private let reactionRepository: AmityReactionRepository
    
    init(client: AmityClient) {
        self.reactionRepository = AmityReactionRepository(client: client)
    }
    
    func queryReactions(
        referenceType: AmityReactionReferenceType,
        referenceId: String,
        reactionName: String? = nil,
        completion: @escaping (Result<[AmityReaction], Error>) -> Void
    ) {
        let query = reactionRepository.getReactions(
            referenceType: referenceType,
            referenceId: referenceId,
            reactionName: reactionName
        )
        
        query.observe { [weak self] collection, error in
            if let error = error {
                completion(.failure(error))
            } else if let reactions = collection?.object {
                completion(.success(reactions))
            }
        }
    }
}

Reaction Aggregates

Each content item provides built-in reaction aggregate data:
Type: numberDescription: Total number of reactions on the content, regardless of type.Use Case: Display overall engagement metrics and popularity indicators.
Type: string[]Description: Array of reaction names that the current user has added to the content.Use Case: Highlight user’s own reactions in the UI and enable toggling.
Type: Record<string, number>Description: Map showing count of each reaction type on the content.Example:
{
  "like": 15,
  "love": 8,
  "wow": 3,
  "angry": 1
}

Live Reaction Updates

Subscribe to live reaction updates for real-time UI synchronization:
// TypeScript example for live reaction updates
const subscription = client.subscribeToReactions({
    referenceType: 'POST',
    referenceId: 'post_123'
}, (updatedReactions) => {
    // Update UI with new reaction data
    updateReactionDisplay(updatedReactions);
});

// Clean up subscription
subscription.unsubscribe();

Analytics & Insights

Engagement Metrics

Track reaction rates, popular content, and user engagement patterns

Sentiment Analysis

Analyze reaction types to understand community sentiment and mood

User Behavior

Identify most active reactors and engagement leaders

Content Performance

Measure which content types and topics generate most reactions

Engagement Analytics Example

interface EngagementAnalytics {
  totalReactions: number;
  uniqueReactors: number;
  averageReactionsPerUser: number;
  reactionDistribution: Record<string, number>;
  engagementRate: number;
  timeBasedMetrics: {
    peakHours: number[];
    dailyAverages: Record<string, number>;
  };
}

const analytics = generateEngagementAnalytics(reactions);

Best Practices

  • Implement pagination for large reaction lists
  • Use reaction aggregates instead of full queries when possible
  • Cache frequently accessed reaction data
  • Implement efficient filtering and sorting on the client side
  • Show loading states during reaction queries
  • Implement optimistic updates for better responsiveness
  • Display reaction summaries before detailed lists
  • Provide filtering options for different reaction types
  • Regularly refresh reaction data for accuracy
  • Handle real-time updates gracefully
  • Implement proper error handling and retry logic
  • Use appropriate data structures for reaction storage
  • Track reaction query patterns for insights
  • Monitor popular content and engagement trends
  • Analyze reaction velocity and patterns
  • Implement A/B testing for reaction features

Error Handling

  • Network Failures: Handle offline scenarios and poor connectivity
  • Invalid References: Non-existent content or invalid IDs
  • Rate Limiting: Too many queries in a short period
  • Permission Errors: Insufficient access to reaction data
  • Implement exponential backoff for failed queries
  • Cache successful results for offline scenarios
  • Provide fallback UI when queries fail
  • Show appropriate error messages based on error type