atomsite.net

The AtomPub server for .NET

Annotations and Comments

Posted in About, Features, Technical by JarrettV on 3/21/2009 3:46:00 PM - CST

Overview

AtomSite has full featured support for annotations (also known as comments). Annotations can be turned on/off at the collection level or individual entry level. You can require annotations to be approved before they are visible. AtomSite is built to support paging and threading of annotations. AtomSite supports annotations in accordance with Atom Threading Extension.

Control

AtomSite supports multiple methods for controlling if an entry supports annotations. The first method is by modifying the configuration setting called annotationsOn on the collection.

annotationsOn
true = annotations are on
false = annotations are off

You can gain granular control over who is allowed to annotate by changing the role matrix at either the service, workspace or collection level. As shown below, the default role matrix allows anyone to annotate.

<svc:roleAction name='Annotate' admin='True' author='True' contrib='True' user='True' anon='True'/>

You can also control annotations at the entry level by the allowAnnotate setting on each entry.

Finally, annotations can be controlled by an expiration date set by the annotateDaysOpen setting.* Annotations on an entry will appear closed after X number of days past the published date.

Approvals

When an annotation is created, the annotation may be automatically approved depending on their role. As seen below in the default role matrix, users and anonymous users comments must be approved by an administrator, author, or contributor.

<svc:roleAction name='ApproveAnnotation' admin='True' author='True' contrib='True' user='False' anon='False'/>

Annotations that have not been approved will only show to authorized users. The unapproved annotations will show up as red. When the annotation is successfully approved, it fades to green (via jQuery). The website supports approving individual annotations or all annotations at the same time.

Paging

AtomSite was designed to support paging comments. This is valuable when an entry has too many annotations that may slow the page down. The backend and service layer already support paging.  In the future, a theme will be available that supports this paging on the front-end.

Threading

As mentioned earlier, annotations are created by posting an entry to any existing entry. Since every annotation is an entry, this allows you to thread the entries. In the blogosphere, this is known as nested comments.

The backend does support threading comments. However, there is not yet first class support for this on the front-end. It is scheduled for a future release.

Technical

AtomSite supports new annotations by posting an entry to the address of any existing entry. The user's browser talks directly to the service using an ajax request.

POST /blog/2008/08/24/BlogSvcNowSupportsComments.atom HTTP/1.1
x-requested-with: XMLHttpRequest
Accept-Language: en-us
Referer: http://atomsite.net/blog/2008/08/24/BlogSvcNowSupportsComments.xhtml
Accept: application/xml, text/xml, */*
Content-Type: application/atom+xml;type=entry
UA-CPU: AMD64
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Win64; x64;
.NET CLR 2.0.50727; SLCC1; .NET CLR 3.5.21022; .NET CLR 3.5.30428; .NET CLR 3.5.30729)
Host: blogsvc.net
Content-Length: 196
Connection: Keep-Alive
Pragma: no-cache
Cookie: ASP.NET_SessionId=fr1fix55vfyqiivzypp05b55

<entry xmlns='http://www.w3.org/2005/Atom'>
  <title>Comment</title>
  <author>
    <name>Test</name>
    <email>test@test.com</email>
    <uri>http://test.com</uri>
  </author>
  <content type='html'>Test</content>
</entry>
HTTP/1.1 201 Created
Cache-Control: private
Content-Type: text/plain
Location: http://atomsite.net/blog/2008/08/24/BlogSvcNowSupportsComments/Comment.atom
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Sun, 24 Aug 2008 20:47:19 GMT
Content-Length: 67

..snip..

The response will now contain a cookie to remember anonymous user details. If the request is from an AJAX call it will return the html to add the web page, otherwise it will return the Atom entry.

$.ajax({
  type: "POST",
  url: "<%= AnnotationHref %>",
  data: "<entry xmlns='http://www.w3.org/2005/Atom'>
      <title>Comment</title>
      <author>
        <name>" + parse($('#txtName').val()) + "</name>
        <email>" + encodeURI($('#txtEmail').val()) + "</email>
        <uri>" + encodeURI($('#txtWebsite').val()) + "</uri>
      </author>
      <content type='html'>" + parse($('#txtComment').val()) + "</content>
    </entry>",
  contentType: "application/atom+xml;type=entry",
  dataType: "xml",
  complete: function(req) {
    if (req.status == 201) {
      reset();
      $.ajax({
        url: "/blog/<some entry>.atom" + req.responseText,
        success: function(html) {
          $(html).hide().appendTo("#annotations").addClass("annotationSelf").fadeIn("slow");
        }
      });
    } else {
      alert('Failed to post comment: ' + req.statusText);
    }
  }
});

*This feature will be available in future version.

© Copyright 2012 Powered by AtomSite 1.4.0.0