social.plus SDK provides functionality to retrieve comments from your application. You can retrieve a single comment by its ID or multiple comments in batch operations. The retrieved results are returned as live objects, providing real-time updates when comment data changes.

Single Comment

Fetch individual comments by ID with live object updates

Multiple Comments

Retrieve multiple comments efficiently with batch operations

Live Objects

Real-time synchronization with automatic updates
Comments are returned as live objects, which automatically update when the underlying data changes. For more information, refer to the Live Objects/Collections documentation.

Comment Properties

When you retrieve a comment, you get access to various properties and metadata.
PropertyTypeDescription
commentIdStringUnique identifier for the comment
userIdStringID of the user who created the comment
postIdStringID of the post this comment belongs to
parentIdString?ID of parent comment (for replies)
textString?Text content of the comment
createdAtDateWhen the comment was created
editedAtDate?When the comment was edited (if applicable)
reactionsCount[String: Int]Count of reactions by type
childrenCountIntNumber of reply comments

Parameters

ParameterTypeRequiredDescription
commentIdStringYesUnique identifier of the comment to retrieve
import AmitySDK

// Initialize comment repository
let commentRepository = AmityCommentRepository(client: AmityUIKitManager.client)

// Retrieve a single comment
let commentLiveObject: AmityObject<AmityComment> = commentRepository.getComment(withId: "comment_id")

// Observe comment updates
commentLiveObject.observe { [weak self] liveObject, error in
    guard let self = self else { return }
    
    if let error = error {
        print("Error retrieving comment: \(error.localizedDescription)")
        return
    }
    
    if let comment = liveObject.object {
        // Comment retrieved successfully
        self.displayComment(comment)
    }
}

Multiple Comments Retrieval

For retrieving multiple comments, you can iterate through an array of comment IDs:
var token: AmityNotificationToken?

func commentQueryExample() {
    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 result
    }
}