How can I find and remove comments/additions?

I need to search for all comments/annotations to which there is a reply.
I have a script that searches for comments with a given content

{{velocity}}
#set($q1 =$services.query.xwql("select distinct doc.fullName from Document doc, doc.object(XWiki.XWikiComments) com WHERE com.comment LIKE :value "))

#set($cos = $q1.bindValue(‘value’, ‘%MyWord%’).execute())

#foreach($convertableDoc in $cos)
* [[$convertableDoc>>$convertableDoc]]
#end

{{/velocity}}

How can I find the comments that have been replied to ?
How can I delete a comment and replies?
Please help

Hello, you can check the xproperties available in the XWiki.XWikiComments xclass by checking https://<yourserver>/xwiki/bin/view/XWiki/XWikiComments in your XWiki instance.

Screenshot 2023-06-06 at 15.05.18

The replyto xproperty could be used to do what you need I think.

Thanks

By removing the xobjects from the document.

I know how to delete all comments for a page.
But how do I delete only the comment I’m interested in?

#foreach($d in $xwiki.wrapDocs($xwiki.searchDocuments(", BaseObject obj where obj.name = doc.fullName and obj.className = ‘XWiki.XWikiComments’ and doc.fullName = ‘Test.test.Web.home’ ")))
#if($d.removeObjects(‘XWiki.XWikiComments’))
$d.save()
* Removed comments from [$d ]
#end
#end

You should define what are you interested in:

  • comment posted by a specific user
  • comment that is a reply to a specific comment
  • comment posted at/before/after a given date
  • comment having some specific content
  • comment having a known id

You have this information in the comment object and you can use it

Hope it helps,
Alex

Hi,
I know the comment is a reply to another comment but I don’t know how to find out which comment is the previous one.
ReplyTo doesn’t resolve my problem becouse I have only information that this is a comment with a reply…

my properties from comment object

<property><date>Fri Jun 16 15:08:36 CEST 2023</date></property>
<property><highlight></highlight></property>
<property><selection></selection></property>
<property><selectionLeftContext></selectionLeftContext></property>
<property><author>XWiki.Test</author></property>
<property><replyto>0</replyto></property>
<property><comment>#Reply comment</comment></property>
<property><selectionRightContext></selectionRightContext></property>
<property><state></state></property>
<property><originalSelection></originalSelection></property>
<property><target></target></property>

It does. It contains the number of the comment xobject that it’s a reply to. Just try to write a few comments and look at them in the xobject editor and you’ll see.