How to get total comments related to a reference ID?

I would like to get the total number of comments associated with a referenceID, but I do not see any docs pointing to it.

Currently, it seems we are able to get comments related to a Post (saw on iOS docs), however for my case, I am not using post. I just use the comment feature with referenceID.

Can someone point me to the correct way to get the total count of the comments, please?

ref: Docs Link

Hi @sijanshs! Thank you for the question.

Same as for the iOS SDK, on Web SDK you can access the total number of comments if they are attached to the Post.
It is not mentioned in Web SDK documentation yet. We will make sure to fix it soon.

However, in relation to your use case, I can not give an answer right now. I have reached out to the development team to provide the latest update on the API in the development and to double-check is there a way for you to achieve the desired outcome at the moment. We will get back to you withing tomorrow.

At the same time, if you can provide more information about your use case and an example of parameters you send when you create a comment - it might help the team to advise you with potential workarounds.

Thanks for the quick feedback.

In my case, we do not have any posts.
We just use a reference ID related to our page, to store comments related to it.

We use the basic createComment the SDK has exposed,

const commentLiveObject = CommentRepository.createTextComment({
  referenceType: 'content',
  referenceId: 'pageID',
  text: 'Hello World!',
});

As you can see, the referenceID can be anything, is not tied to a post, which is the correct use for us.

However, to get the total comments related to the referenceID i found that is not documented.

There is a way to get it via post’s total comment count but since we do not use post, we do not have any tie with post and comment.

Is there some patch or fix otw for this use case?

1 Like

Hi @sijanshs ,

The Standalone Comment concept what you are using when you create a comment with
referenceType: 'content' actually creates a post in the background with the content type. Shortly, Content Post identifies that the post belongs to an external source, and SDK does NOT keep the Post data. Or in other words, we can say that this Post is “virtual” and represents the entity of content in your system.

You can see these post entities by Amity Console as well:

As a conclusion of it - you can actually access this post from SDK side:

import { PostRepository } from 'eko-sdk';

let commentsCount = 0;

// Note, that here I am using 'pageID' - the value
// you set to referenceId argument when you create the comment
const postLiveObject = PostRepository.postForId('pageID');

postLiveObject.once('dataUpdated', postData => {
  commentsCount = postData.commentsCount;
});

I hope it solves your use case.

P.S.: The behavior that I described above is not represented in documentation yet. I have opened a ticket to update the documentation.

Hello @Jenya ,

I did try your suggested solution. here is the result

step to reproduce ( on eko-sdk version 4.4.3 )

  1. create a comment with an refID and referenceType content.
  2. getting a post by the refID.
  3. getting post is error and the model data is undefined

as show in the image below.

also tried with the referenceType post the result was the same as above.

1 Like

Could you please kindly help pointing to the correct documentation with this issue as we are unable to get the post currently as @jing mentioned above.

Any suggestion or workound will be highly appreciated.

1 Like

Hello @jing and @sijanshs !

We found a bug which prevented the post “content” to be fetched from the sdk. A patch has already been issued and should be included in the next release.

I’ll update this question when the updated working code is released!

Thanks a lot for your patience,
Julien

1 Like

Hello @jing and @sijanshs

Our latest 5.1.0 version contains the patch for this.
Please let me know if you have trouble using it!

1 Like

@Julien Thank you very much