HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Define a comment

Shows how to define a comment in the Optimizely Community API platform.

In the Optimizely Community API, a comment is represented with the Comment class.

An instance of the Comment class is constructed with:

  • Author – The user submitting the comment identified with an instance of the Reference class. The author is assumed to be anonymous if an empty Reference is provided.
  • Body – The content of the comment represented as a string.
  • Parent – The entity to which the comment is related, identified with an instance of the Reference class. This parent may identify a resource, such as content, a product in your application, or another comment.
  • IsVisible – Indicates whether this comment is intended to be presented within the application, represented as a Boolean.

An instance of the Comment class, contributed by an anonymous user, can be constructed as shown below:

var parentContent = Reference.Create("resource://identifier/for/a/resource");
var body = "This is wonderful content!";
var isVisible = true;

var comment = new Comment(parentContent, body, isVisible);

An instance of the Comment class, contributed by a known user, can be constructed as shown below:

var parentContent = Reference.Create("resource://identifier/for/a/resource");
var author = Reference.Create("user://identifier/for/a/user");
var body = "This is wonderful content!";
var isVisible = true;

var comment = new Comment(parentContent, author, body, isVisible);

If an instance of a comment is intended to be a reply to an existing comment, it can be constructed as shown below:

Comment existingComment;

// ...

var parentComment = existingComment.Id.ToReference();
var author = Reference.Create("user://identifier/for/a/user");
var body = "This is wonderful content!";
var isVisible = true;

var comment = new Comment(parentComment, author, body, isVisible);

Parents and ancestors

Comments are hierarchical, so share relationships with resources and other comments.

A comment has a parental relationship. The parent of a comment is the entity to which the comment replies. That entity may be a resource, such as content, a product, or another comment. In the diagram above:

  • The parent of Comment 1 is Resource.
  • The parent of Comment 3a is Comment 3.

A comment also has ancestral relationships. A comment's ancestor is any entity appearing in the comment's hierarchical lineage. As with the parental relationship, ancestors may include a resource, such as content or a product, and other comments.

In the diagram above:

  • The ancestors of Comment 1a include Resource and Comment 1. Conversely, Comment 1a may be referred to as a descendant of Resource and Comment 1.
  • The ancestors of Comment 3 include only Resource.

The Optimizely Community API supports retrieving comments according to parent and ancestral relationships. See Retrieve a Comment in Manage comments.

Identify the parent of a comment

The parent of a comment may identify one of two things:

  • A resource, such as content or a product in your application
  • Another comment

A comment directly attributed to a particular application resource identifies that resource as its parent. In such a case, an instance of the Reference class is constructed to identify that resource and is specified through the Comment class's constructor. (For information about references, see References and IDs in Discovering the platform.

A comment representing a reply to an existing comment identifies the original comment as its parent. In these cases, an instance of the Reference class is constructed with the ID of the parent comment and specified through the Comment class's constructor.