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.

namespace EPiServer.Social.Comments.Core
{
    //
    // Summary:
    //     The Comment class represents an individual instance of user-generated content
    //     within the Episerver Social platform.
    public class Comment
    {
        //
        // Summary:
        //     Constructor
        //
        // Parameters:
        //   parent:
        //     Reference uniquely identifying the parent entity for the comment
        //
        //   body:
        //     Body content of the comment
        //
        //   isVisible:
        //     Indicates whether or not this comment is intended to be displayed
        public Comment(Reference parent, string body, bool isVisible);
        //
        // Summary:
        //     Constructor
        //
        // Parameters:
        //   parent:
        //     Reference uniquely identifying the parent entity for the comment
        //
        //   author:
        //     Reference uniquely identifying the user who contributed the comment
        //
        //   body:
        //     Body content of the comment
        //
        //   isVisible:
        //     Indicates whether or not this comment is intended to be displayed
        public Comment(Reference parent, Reference author, string body, bool isVisible);
        //
        // Summary:
        //     Constructor
        //
        // Parameters:
        //   id:
        //     Unique identifier for the comment
        //
        //   parent:
        //     Reference uniquely identifying the parent entity for the comment
        //
        //   author:
        //     Reference uniquely identifying the contributor of the comment
        //
        //   body:
        //     Body content of the comment
        //
        //   isVisible:
        //     Indicates whether or not this comment is intended to be displayed
        public Comment(CommentId id, Reference parent, Reference author, string body, bool isVisible);

        //
        // Summary:
        //     Gets a collection of references representing the ancestral  path for this comment.
        //     The references identify ancestors in order from the root entity to this comment's
        //     parent.
        public IEnumerable<Reference> Ancestors { get; }
        //
        // Summary:
        //     Gets a reference uniquely identifying the user who contributed this comment.
        public Reference Author { get; }
        //
        // Summary:
        //     Gets the body content of the comment.
        public virtual string Body { get; }
        //
        // Summary:
        //     Gets the date (UTC) on which this comment was added.
        public DateTime Created { get; }
        //
        // Summary:
        //     Gets a boolean indicating whether or not this comment has any replies.
        public bool HasChildren { get; }
        //
        // Summary:
        //     Gets a boolean indicating whether or not this comment has any replies, which
        //     are also visible.
        public bool HasVisibleChildren { get; }
        //
        // Summary:
        //     Gets the unique identifier for this comment.
        //
        // Remarks:
        //     This identifier is generated automatically by the Episerver Social platform.
        public CommentId Id { get; }
        //
        // Summary:
        //     Gets a boolean indicating whether or not this comment is intended to be displayed.
        public virtual bool IsVisible { get; }
        //
        // Summary:
        //     Gets a reference uniquely identifying the parent entity for the comment. The
        //     parent entity may be a resource within your application, such as content or a
        //     product. If this comment is intended to represent a reply to an existing comment,
        //     the parent reference should identify that existing parent.
        public Reference Parent { get; }
    }
}

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