Can inline comments be converted to page comments?

Inayat Nahvi April 27, 2023

Hi,

We have a confluence page that has several inline comments (around 15).   Is there a mechanism to convert them all to page comments?  And retain the comment author and dates?

Thanks.

2 answers

1 accepted

0 votes
Answer accepted
Andrii Maliuta
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.
April 27, 2023

Hello @Inayat Nahvi ,

Yes, this can be possible with Confluence Java API. You just need to define what data to save (line highlighted content for inline comment) if it should be saved in the body of the page bottom comment or not.

You can use:

  1. ScriptRunner (if installed)
  2. Create custom addon
  3. Use REST API client and Confluence REST API (a little more hand work)

Smth like:

PageManager pageManager = ComponentLocator.getComponent(PageManager.class);
CommentManager commentManager = ComponentLocator.getComponent(CommentManager.class);
Page page = pageManager.getPage(111);
page.getComments().forEach(comment -> {
if (comment.isInlineComment()) {
comment.setInlineComment(false);
comment.setContainer(page);
commentManager.saveContentEntity(comment, DefaultSaveContext.SUPPRESS_NOTIFICATIONS);
}
});
Inayat Nahvi April 27, 2023

Thanks @Andrii Maliuta .  We have Scriptrunner for Jira, but not Confluence.   Do you think this might be possible with the Confluence CLI plugin? 

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 27, 2023

Also, I'm not ScriptRunner expert, but wouldn't this lose the original comment author and timestamp?

(Like, does the comment function allow you to override author/timestamp? Seems like you'd need admin rights for that, if it's possible at all.)

Andrii Maliuta
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.
April 27, 2023

@Darryl Lee !

Thanks for the comment :)

>> but wouldn't this lose the original comment author and timestamp

[AM] here just 2 props are updaetd and the same comment with all the previous data is passed to saveContentEntity method. But yes, it is always needs to be TESTED first :) There are other methods/approaches to try.

>> (Like, does the comment function allow you to override author/timestamp? Seems like you'd need admin rights for that, if it's possible at all.)

[AM] Yes, if you are comment author or space admin where comments are located or Confluence admin - it should be work.

Andrii Maliuta
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.
April 27, 2023

@Inayat Nahvi , as for the CLI app:

It can be possible to

1. create comments from inline ones:

2. remove the original ones

like:

--action runFromCommentList --space "SPACE_KEY" --title "PAGE_TITLE" \
--common "-a addComment --space "SPACE_KEY" --title "PAGE_TITLE" --comment @commentId@"

this is just a sketch :)

If highly required, I can try to practice to find the solution :) 

1 vote
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 27, 2023

So full disclosure, I work with @Inayat Nahvi, and after he posted this question, I found this ticket CONFSERVER-38240 which included a very clever Bookmarklet (Javascript snippet that works as a Bookmark) created by @Andrei Mitin

With the click of a button in the browser, you can have inline comments show up at the bottom of the page as if they were regular comments. Even more interestingly, @Immanuel Comer had the idea to add this to Custom HTML in the End of Body section (surrounded by <script> tags), so this would show for every page. This is probably too much for our use case. Would be nice if I could do this on a per space basis.

I made a tweak to the Javascript to include the timestamp (which sadly only shows a date after I guess 24 hours?), and I'm actually pretty happy with how it turned out. Not sure if it we'll actually implement it though, as I'm sure people will complain about double-comments.

Screen Shot 2023-04-27 at 12.50.36 PM.png

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 27, 2023

Updated Javascript to include timestamps:

javascript&colon;$('[class^=icg-]').remove();
$('[class*=icgc-]').each(function(){
$(this).removeClass('icgc-resolved').removeClass('icgc-unresolved');
});

$(document.head).append('<style class="icg-style">' +
'.icgc-resolved { -webkit-print-color-adjust: exact; background-color: #afa; }' +
'.icgc-unresolved { -webkit-print-color-adjust: exact; background-color: #ffa; }' +
'</style>');
$.get( '/rest/inlinecomments/1.0/comments?containerId=' + $('[name=treePageId]').val() + '&_=' + new Date().getTime(), function (data, textStatus, xhr) {
$('#comments-section').append('<h1 class="icg-h" style="page-break-before: always">Inline comments</h1>');
$('#comments-section').append(data.map(function(comment, index) {
var resolved = comment.resolveProperties.resolved === true;
return '<div class="icg-c" id="icg-c-' + comment.markerRef + '" data-commentid="' + comment.id + '" data-index="' + (1 + index) +
'" style="margin-top: 20px; padding-top: 10px; border-top: solid 1px #ddd">' +
'<a href="#icg-s-' + comment.markerRef + '"><b class="' + ( resolved ? 'icgc-resolved' : 'icgc-unresolved' ) + '">' + (1 + index) + '. ' + ( resolved ? '[resolved] ' : '' ) + comment.authorDisplayName + ' (' + comment.lastModificationDate + ')' + '</b></a>:<br/>' + comment.body + '</div>';
}).join(''));

$('.icg-c').each(function(){
var $cdiv = $(this);
var commentId = $cdiv.data('commentid');
$.get( '/rest/inlinecomments/1.0/comments/' + commentId + '/replies?_=' + new Date().getTime(), function (data, textStatus, xhr) {
$cdiv.after(
data.map(function(comment, index) {
return '<div class="icg-c-r" style="margin-top: 10px; border-top: solid 1px #eee; margin-left: 30px; padding-top: 10px"><b>' +
comment.authorDisplayName + ' (' + comment.lastModificationDate + ')' + '</b></a>:<br/>' + comment.body + '</div>';
}).join(''));
});
});

$('.inline-comment-marker').each(function(){
var $this = $(this);
var ref = $this.data('ref');
$this.attr('id', 'icg-s-' + ref).addClass( $this.hasClass('valid') ? 'icgc-unresolved' : 'icgc-resolved' );
$this.after($('<sup class="icg-f"><a href="#icg-c-' + ref + '">[' + $('#icg-c-' + ref).data('index') + ']</a></sup><span> </span>'));
});
});
(function(){})();
Like Andrii Maliuta likes this
Andrii Maliuta
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.
April 28, 2023

Hi @Darryl Lee ,

Thank you for the update. Yes, it is possible to change the look as you want with AJS/JS, though it influences the UI . Please note that AJS/AUI can change when new  major versions are released and you will have to adapt the code  - https://aui.atlassian.com/aui/latest/docs/upgrade-guide.html

There is this app that gathers comments in UI menu and in macro s table and then you can export them, but it is PAID  - https://marketplace.atlassian.com/apps/1219786.

I suppose such gathering of comments can be done in many ways and it depends on how it will be maintained :) We usually do this in custom apps that have in companies internally.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.16.4
TAGS
AUG Leaders

Atlassian Community Events