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.
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:
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);
}
});
Thanks @Andrii Maliuta . We have Scriptrunner for Jira, but not Confluence. Do you think this might be possible with the Confluence CLI plugin?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Updated Javascript to include timestamps:
javascript:$('[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(){})();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.