Resolved comments disappear. Bug or by design? + our Comments database set-up

I don’t think the URL field can be made to open a link in an adjacent panel, but I’ll note that as a feature request.

If you modify the code (for the second automation script) as follows, the URL will be appended with an anchor which will take the user to the comment (or at least to the first paragraph in the comment if there are multiple).
(note: this may not be the paragraph that contains a specific user mention)

const fibery = context.getService('fibery');

function getMentions(text) {
    const regex = /(?<=\[\[#\@[a-f0-9-]+\/)[a-f0-9-]+/g;
    const found = text.match(regex);
    return found;
}

function findAnchor(text) {
    const regex = /(?<=^<p data-guid=")[a-f0-9-]+/g
    const found = text.match(regex);
    return found;
}

for (const entity of args.currentEntities) {
    const entityWithSecret = await fibery.getEntityById(entity.type, entity.id, ['Comment secret','URL']);
    const content = await fibery.getDocumentContent(entityWithSecret['Comment secret'], 'md');
    const matches = getMentions(content);
    if (matches) {
        for (const match of matches) {
            await fibery.addCollectionItem(entity.type, entity.id, 'Mentions', match);
        }
    }
    const contenthtml = await fibery.getDocumentContent(entityWithSecret['Comment secret'], 'html');
    const anchor = findAnchor(contenthtml);
    await fibery.updateEntity(entity.type, entity.id, { 'URL': entity['URL'] + '/anchor=' + anchor });
}

Comment: as well as adding the anchor functionality, I added a bit of code to prevent errors which would occur if there were no @mentions in the comment.

Certainly seems like not the ideal behaviour(!)
Will look into this.

I checked, it’s a known bug

1 Like