Comment Architecture

Enablement, requirements, and options

Enable Comments

A quick trip to author/settings.html will allow you to enable comments. Once enabled, there will be a new section on the settings page to configure commenting options.

Important Notes:

  • If comments are enabled site-wide, all previous posts will have comments turned on by default.
  • If you wish to disable commenting on a post, you can do so by visiting the post and disabling the icon in the lower left hand corner.
  • If you decide to disable commenting site-wide, previous comments will still be stored in the JCR, but they will no longer show on any post.

Options & Requirements

Options are kept straight-forward. Google reCAPTCHA is a hard requirement to prevent spam.

  • Default Comment Status - This is used to determine whether to hold all comments for moderation or to allow immediate publish.
  • Google reCAPTCHA Site Key - Required - This site key enables reCAPTCHA services.
  • Google reCAPTCHA Secret Key - Required - This secret key enables reCAPTCHA services.

Publish Views

All comment related views are handled as AJAX calls against a specific end-point. The primary reason for this is to keep pages in cache, while still being able to keep up-to-date comment information site-wide.

Example Request

http://localhost:8080/posts/hello-world.list.comments.json


Example Response

As you can see, the response also contains the comment count in the payload. This reduces the amount of requests needed to get comments for a specific post.

Other Developer Notes

Within a given article tag, there are several properties to define what comment values should be pulled into a view. In the case of a list view, only the comment count is pulled in. In the case of a detail view, both the comment count and the list are pulled in. They are defined using data attributes.


How comments appears to a visitor


  1. The comments count is pulled via AJAX from hello-world.list.comments.json
  2. The comments list is also pulled from hello-world.list.comments.json
  3. reCAPTCHA is wired up through site and secret keys specified in author/settings.html
  4. When a comment is successfully created, the comment compose box will be removed, the comment will be posted to the page, and the cache will be evicted for the comment list end-point.

Author Views

All comment moderation happens in author/comments.html. Selecting a comment will expand the details for further refinement. Want to change status or edit the comment itself? All of that can be done here. Deleting of comments leverages the same ItemDeleteServlet used for pages and posts. Pagination also works very similarly to post and page authoring list views.


Areas of interest for developers

Below are some tidbits developers might be interested in.

  • Comments are created using a rep:SystemUser that is created in Activation.java - I.E. No resolverFactory.getAdministrativeResourceResolver
  • Comments are stored in /content/slick/publish/comments/{slickType}/{item-name}/{comment-guid} This allows us to set a single permission level for all comments.
  • There is a CommentService (and implementation) that performs most of the list and creation of comments. The EditCommentServlet is used to validate the captcha. This area of concern may shift a little in the future.
  • Comment deletion is using the existing ItemDeleteServlet.
  • Most of the front-end is a combination of raw XHR, Handlebars, and JS. Much like the rest of Slick's client library stack.