Build powerful comment systems with advanced querying capabilities including thread filtering, real-time updates, pagination, and flexible sorting options. The social.plus SDK provides comprehensive comment retrieval with Live Collections for optimal performance.
Comment queries return Live Collections that automatically update when comments are added, edited, or deleted, providing real-time updates across all connected clients.

Common Use Cases

Social Media

Load parent comments with expandable replies, and infinite scroll for engaging social discussions.

News Comments

Display chronological comments with sorting options, moderation features, and user reputation indicators.

Forum Discussions

Implement threaded discussions with unlimited nesting, search functionality, and user mention notifications.

Product Reviews

Show product feedback with rating filters, verified purchase indicators, and helpful vote sorting.
Always implement proper pagination to ensure optimal performance and user experience. Consider your application’s specific threading requirements when choosing between flat, two-level, or infinite threading strategies.

Reference Types

Comments can be queried from different types of content by specifying the appropriate reference type.
Reference TypeDescriptionUse Cases
postComments on regular postsSocial media feeds, blog posts, news articles
storyComments on story contentTemporary content, social stories
contentComments on specialized contentMedia galleries, documents, custom content

Query Options

The ability to query comments and their replies is essential for creating robust commenting experiences. Use various parameters to filter and organize comments based on your application’s needs.
ParameterTypeDescription
referenceIdStringID of the content being commented on (post, story, etc.)
referenceTypeEnumType of content (.post, .story, .content)
parentIdString?Filter by parent comment ID (null for top-level comments)
includeDeletedBooleanWhether to include deleted comments in results
dataTypesArrayFilter by comment content types (text, image, etc.)
// Query all comments on a post
let queryOptions = AmityCommentQueryOptions(
    referenceId: "post-id",
    referenceType: .post,
    filterByParentId: false,
    orderBy: .descending,
    includeDeleted: false
)

token = commentRepository.getComments(with: queryOptions)
    .observe { collection, changes, error in
        // Handle the Live Collection results
        if let error = error {
            print("Error querying comments: \(error.localizedDescription)")
            return
        }
        
        // Process comments
        let comments = collection.object
        updateCommentsUI(comments)
    }

Comment Threading

Top-Level Comments

Query parent-level comments by setting parentId to null:
// Query only top-level comments
let queryOptions = AmityCommentQueryOptions(
    referenceId: "post-id",
    referenceType: .post,
    parentId: nil, // Top-level comments only
    orderBy: .descending,
    includeDeleted: false
)

Reply Comments

Query replies to a specific comment by providing the parent comment ID:
// Query replies to a specific comment
let queryOptions = AmityCommentQueryOptions(
    referenceId: "post-id",
    referenceType: .post,
    parentId: "parent-comment-id", // Replies to this comment
    includeDeleted: false
)

Content Type Filtering

Filter comments by their content types using the dataTypes parameter:

Filter Options

Filter TypeDescriptionExample Use Case
anyComments containing at least one specified typeShow comments with images OR text
exactComments containing all specified typesShow comments with images AND text
// Query image comments only
let queryOptions = AmityCommentQueryOptions(
    referenceId: "post-id",
    referenceType: .post,
    dataTypes: [.image], // Image comments only
    filterByParentId: false,
    orderBy: .descending
)