Article Comments

The ICommentableContentType  plugin type enables comments to be created for your content type.

Why should I support comments?

When considering social features comments can be a great way to allow users to provide feedback. One example is if you were creating a shopping cart and wanted to allow comments on your products. In this sample comments can be added to links. This can be used as a way to allow users to add feedback on the content in the links.

Creating an ICommentableContentType plugin

To add support for commenting implement the ICommentableContentType Plugin Type that is defined in the Telligent.Evolution.Extensibility.Content.Version1 namespace. For the following example, we'll add the ICommentableContentType to the existing content type defined in the Content Type Example , updating the LinkItemContentType definition to:

public class LinkItemContentType : IContentType, ITranslatablePlugin, ICommentableContentType

The ICommentableContentType interface defines four members: CanCreateComment(), CanReadComment(), CanModifyComment(), CanDeleteComment(). These methods define the logic that allows a user to create, read, modify, and delete comments associated to content defined by the IContentType . The following implementation of ICommentableContentType can be added to the LinkItemContentType implementation. For this sample we'll implement logic such that:

  • Any user can read comments.
  • Any non-system account can create comments.
  • The author or group manager (user with Manage Group permissions) can edit or delete comments.

#region ICommentableContentType

public bool CanCreateComment(Guid contentId, int userId)
{
	var user = Telligent.Evolution.Extensibility.Apis.Get<IUsers>().Get(new UsersGetOptions { Id = userId });
	return user?.IsSystemAccount == false;
}

public bool CanReadComment(Guid commentId, int userId)
{
	return true;
}

public bool CanModifyComment(Guid commentId, int userId)
{
	var comment = Telligent.Evolution.Extensibility.Apis.Get<IComments>().Get(commentId);
	if (comment == null)
		return false;

	if (comment.UserId == userId)
		return true;

	var modifyGroupPermissionId = Telligent.Evolution.Extensibility.Apis.Get<IGroupPermissions>().ModifyGroup;
	var permissionCheck = Telligent.Evolution.Extensibility.Apis.Get<Telligent.Evolution.Extensibility.Api.Version2.IPermissions>().CheckPermission(modifyGroupPermissionId, userId, new Telligent.Evolution.Extensibility.Api.Version2.PermissionCheckOptions
	{
		ContentId = comment.Content.ContentId,
		ContentTypeId = comment.Content.ContentTypeId
	});

	return permissionCheck.IsAllowed;
}

public bool CanDeleteComment(Guid commentId, int userId)
{
	var comment = Telligent.Evolution.Extensibility.Apis.Get<IComments>().Get(commentId);
	if (comment == null)
		return false;

	if (comment.UserId == userId)
		return true;

	var modifyGroupPermissionId = Telligent.Evolution.Extensibility.Apis.Get<IGroupPermissions>().ModifyGroup;
	var permissionCheck = Telligent.Evolution.Extensibility.Apis.Get<Telligent.Evolution.Extensibility.Api.Version2.IPermissions>().CheckPermission(modifyGroupPermissionId, userId, new Telligent.Evolution.Extensibility.Api.Version2.PermissionCheckOptions
	{
		ContentId = comment.Content.ContentId,
		ContentTypeId = comment.Content.ContentTypeId
	});

	return permissionCheck.IsAllowed;
}

#endregion

Once the project is rebuilt and the plugin is  , commenting on link items can be performed using the commenting API.