Creating reply comments also added as first-level comments of a post

Hello Amity,

We want to add a reply comment that belongs to only the parent comment but when we create with the snippet below they also added as a first-level comment of a post and also cannot filter out by using filterByParentId.

        await CommentRepository.createTextComment({
          referenceType: 'content',
          referenceId: post.id,
          text: message.trim(),
          parentId, // parent comment id
        });

for first-level comment we also created as

        await CommentRepository.createTextComment({
          referenceType: 'content',
          referenceId: post.id,
          text: message.trim(),
        });

However, we could fix this by changing the reference type to post for first-level comments as suggested in the document Posts - Amity Docs

so the first-level comment creating snippet would be

        await CommentRepository.createTextComment({
          referenceType: 'post',
          referenceId: post.id,
          text: message.trim(),
        });

so after we change to the post reference type, the reply comment seems fixed but we cannot view our first-level comments in the amity console by clicking the number of comments in the comment column on the post view page which redirects to the comment view page with reference type content by default.

anyway, we found a workaround on this, we change the reference on the top-right on the screenshot to post and copy the post id we want then we could query the post comments.

but If we use reference type content we can view comments on the amity admin panel correctly but we would have an issue with the reply comment mention above.

Please give us suggestions what is the right approach for this story.

1 Like

I’d like to provide more details about the data of live objects we get when we using the content reference type for comment.

we are querying the comments by

    collection.current = CommentRepository.queryComments({
      referenceType: 'content',
      referenceId: post.id,
      last: currentLimit,
      filterByParentId: true,
    });

we can notice that there is a comment that has parentId also return by the query

so our UI would look like

1 Like

Hello @jing,

For the creation of comments at top level, comments as replies, and the matching comment queries, please refer to this demo. I think it will cover 100% of what you were expecting.

Let me know if that worked for you,

Could you try with the real post id as a reference id which the post created with a specific id and the post has target type content?

This would be our current case.

Thank you.

As you can see in the example, the referenceType when creating the comments is equal to “content”, which means a new post will be created while creating the comment.

The targetType for the post will be “content” as well.

In our case,

We create the content post first since sometime users dont make any comments but they make some reactions ( like ) on the post.

Not sure the order would cause indifferent result ?

No, the only difference is that the post already exist before creating the comment, so the post will not be created “on the go”. Otherwise there’s no reason why it would be different :slight_smile:

@Julien

thank you for the code example we just found out that we are not on the latest version 5.2.3 if we change the Amity package to 5.1.0, we can see the problem with parent comments which return 2 items.