Hide menu Last updated: Nov 01 2016
Area: Episerver Social Applies to versions: 1 and higher

Defining a comment

In the Episerver Social platform, 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. If an empty Reference is provided, the author is assumed to be anonymous.
  • 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 or 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 in nature, so share relationships with resources and other comments.

Comment tree

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 or 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 Episerver Social platform supports the retrieval of comments according to parent and ancestral relationships. For more information on retrieving comments, Retrieving a Comment.

Identifying 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 that is 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 more information about references, see References and IDs.)

A comment that represents 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.

Comments