Skip to main content

Fetch Comment Likes

The Fetch Comment Likes feature in the LM iOS SDK enables users to retrieve information about the number of likes received by a specific comment. This functionality allows developers to display the total number of likes on a comment, providing users with social validation and engagement metrics. By incorporating the Fetch Comment Likes feature, developers can enhance the user experience and encourage active participation within the comment section of their application.

Steps to fetch likes on a comment

  1. Create a GetCommentLikesRequest object using GetCommentLikesRequest.builder() class by passing all the required parameters.
  2. Call getCommentLikes() function using the instance of LMFeedClient.
  3. Process the response LMResponse<GetCommentLikesResponse> as per your requirement.
// object of GetCommentLikesRequest
let request = GetCommentLikesRequest.builder()
.postId(ENTER_POST_ID) // post id of comment whose likes are fetched
.commentId(ENTER_COMMENT_ID) // id of comment whose likes are fetched
.page(1) // page number for paginated data
.pageSize(20) // page size for paginated data
.build()
LMFeedClient.shared.getCommentLikes(request) { response in
// response (LMResponse<GetCommentLikesResponse>)
if (response.success) {
// your function to process the response data
processResponse(response.data)
} else {
// your function to process error message
processError(response.errorMessage)
}
}
note

Same function can be used to fetch likes on a reply as well. Just pass the id of the reply as comment id.

Models

GetCommentLikesRequest

VARIABLETYPEDESCRIPTIONOPTIONAL
postIdStringPost ID of the comment whose likes are fetched.
commentIdStringID of the comment whose likes are fetched.
pageIntPage number of paginated like data.
pageSizeIntPage size for paginated like data.

GetCommentLikesResponse

VARIABLETYPEDESCRIPTIONOPTIONAL
likesLike[]List of the likes on the comment.
totalCountIntTotal count of likes on the commnet.
users[String: User]Dictionary of user unique id to user object.