Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I delete the entire thread?

Christopher Yeleighton December 28, 2015

We discuss page content in comments.  The comments are organised into threads.  Sometimes I want to delete the entire thread when the problem being discussed has been resolved.  How do I do that?

 

2 answers

1 accepted

0 votes
Answer accepted
Rodrigo Girardi Adami
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 28, 2015

Hi Christopher,

I could find this feature request to delete multiple comments: https://jira.atlassian.com/browse/CONF-30354

It seems that Confluence doesn't have this functionality yet unfortunately.

Regards,

Rodrigo

Chander Inguva
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2015

Hey Christopher, watch and vote that feature request to get notified when this is applied.

0 votes
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2015

I was thinking how this might be possible with some custom Javascript code, so I wrote some today. Here's the code for anyone who's interested:

(if you just paste it in as it is, it will show for all users.  if you only want to show it for yourself, fill in your username where it says user.name and remove the // on line 3 and 12)

<script>
AJS.toInit(function() {
  // if (AJS.params.remoteUser == "user.name") {
    jQuery(".comment-thread").has("ol").each(function() {
      var commentId = jQuery(this).attr("id").substring(15);
      var totalComments = jQuery('#comment-thread-' + commentId).find(".comment").length;
      var commentsWithPermissions = jQuery('#comment-thread-' + commentId).find(".comment-action-remove").length;
      if ( totalComments == commentsWithPermissions ) {
        jQuery(this).find(".comment-action-remove").first().after('<li class="comment-action-remove-thread"><a href="javascript:void(0)" onclick="removeThread(' + commentId + ');" id="remove-thread-' + commentId + '"><span>Remove Thread</span></a></li>');
      }
    });
  // }
});
var removeThread = function(id) {
  var confluenceVersion = parseFloat(AJS.params.versionNumber.substring(0,3));
  var comments = jQuery('#comment-thread-' + id).find(".comment");
  var removeComments = function(commentIds) {
    if (commentIds.length) {
      var commentId = commentIds.pop();
      if ( confluenceVersion >= 5.5 ) {
        jQuery.ajax({
          type: 'DELETE',
          url: contextPath + '/rest/api/content/' + commentId,
          success: function(response) {
            removeComments(commentIds);
          }
        });
      } else {
        jQuery.ajax({dataType: 'json',
          contentType: 'application/json',
          type: 'POST',
          url: contextPath + '/rpc/json-rpc/confluenceservice-v2/removeComment',
          data: '[' + commentId + ']',
          success: function( response ) {
            removeComments(commentIds);
          }
        });
      }
    } else {
      jQuery('#comment-thread-' + id).fadeOut(1000);
      var splitHeader = jQuery('#comments-section-title').text().trim().split(" ");
      splitHeader[0] = parseInt(splitHeader[0]) - comments.length;
      jQuery('#comments-section-title').text(splitHeader.join(" "));
    }
  }
  var dialog = new AJS.Dialog({
    width: 400,
    height: 170,
    id: "areyousure-dialog",
    closeOnOutsideClick: true
  });
  dialog.addHeader("Are you sure?");
  dialog.addPanel("Panel 1", "<p>You are about to delete " + comments.length + " comments. Continue?</p>", "panel-body");
  dialog.addButton("OK", function (dialog) {
    dialog.hide();
    var commentIds = [];
    comments.each(function() {
      commentIds.push(this.id.substring(8)); 
    });
    removeComments(commentIds);
  });
  dialog.addLink("Cancel", function (dialog) {
    dialog.hide();
  });
  dialog.show();
}
</script>

EDIT: Added confirmation dialog box

EDIT: Only shown to users who have permissions to remove all comments in the thread

EDIT: Simplified and sped up (realized REST call was unnecessary)

EDIT: Now works with all Confluence versions (also 5.4 and lower)

Christopher Yeleighton December 28, 2015

The user name restriction is unsatisfactory, it should use permissions.

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2015

Actually, it will only show the remove thread link for people that have permissions.

Christopher Yeleighton December 28, 2015

Will it be shown to users who may not remove other users’ comments?

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2015

Sorry if I spammed you with a bunch of updates, but it is now much improved. It will only be shown to users who have permission to remove every comment in the thread, it operates faster, and it should now be compatible with all versions of Confluence.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events