CS Dev Guide: Forum Moderation

You know that the forum application in Community Server is the most powerful and important application in it.  There are many features that make this application great and one of them is the rich set of moderation tasks provided for forum moderators and users.

There are many moderation features that you can use in Community Server forums such as approving, deleting and moving a post or joining or splitting a thread.  These are all coming from a set of API that will be covered in this post.

There are some static methods in CommunityServer.Components.Moderate method factory that help you on these moderation tasks.  I use a practical approach to describe important methods in this factory.

In below code, ApprovePostByID() is a method that approves a post by getting its PostID as parameter.  It then creates a ForumPost based on this PostID by the help of Posts.GetPost() method then passes this ForumPost and the UserID of current user (as moderator) to ApprovePost() method in order to approve the post.

void ApprovePostByID(int postID)

{

    CSContext context = CSContext.Current;

 

    ForumPost post = Posts.GetPost(postID, context.User.UserID);

 

    Moderate.ApprovePost(post, context.User.UserID);

}

DeletePostByID() is another method that gets a PostID as its argument and creates a ForumPost for it then calls DeletePost() method to delete this post.  DeletePost() also gets a User object who is the moderate as parameter as well as a string for the reason that you're deleting this post and a Boolean value to specify that if child posts should be deleted as well.

void DeletePostByID(int postID)

{

    CSContext context = CSContext.Current;

 

    ForumPost post = Posts.GetPost(postID, context.User.UserID);

 

    Moderate.DeletePost(post, context.User, "Just another spam!", true);

}

GetForumIDsToModerate() is a function that takes no argument and returns a list of ForumIDs that should be moderated.  This method gets the help of GetForumsToModerate() method to gets a list of Section objects corresponding to forums that should be moderated then adds the identifier of these sections to the result and returns it.

List<int> GetForumIDsToModerate()

{

    List<int> forumIDs = new List<int>();

 

    List<Section> forums = Moderate.GetForumsToModerate();

 

    foreach (Section forum in forums)

    {

        forumIDs.Add(forum.SectionID);

    }

    return forumIDs;

}

The last example is MoveCurrentPost() method which moves the current post to a new forum.  This method gets the identifier of destination forum as parameter as applies MovePost() method in order to move the post.  It creates a ForumPost and passes it to MovePost() method along the identifier of destination forum and a User object for moderator (current user in my example) and a Boolean value to specify that if email notification should be sent to users participated in this thread.

void MoveCurrentPost(int destinationForumID)

{

    CSContext context = CSContext.Current;

 

    ForumPost post = Posts.GetPost(context.PostID, context.User.UserID);

 

    Moderate.MovePost(post, destinationForumID, context.User.UserID, false);

}

Like these methods, other methods in this factory are straightforward and you can find how to use them from the name of methods and parameters.  Most of them have same structure as above methods.

[advertisement] Axosoft OnTime 2008 is four developer tools in one: bug tracking, project wiki, feature management, and help desk. It manages your development process so developers can focus on coding. Installed or Hosted – Free Single-user license -- Free 30-day team trial.

3 Comments : 08.12.07

Feedbacks

 avatar
#1
Dave Burke
08.16.2007 @ 9:12 PM
blog bits This telecommuting job post from a Washington, D.C. firm who's "looking to build a
 avatar
#2
Dave Burke's Community Server Bits
08.16.2007 @ 9:23 PM
Keyvan's newest CS Dev Guide on Forum Moderation with ApprovePostByID(), DeletePostbyID() and Moderate
 avatar
#3
Community Blogs
08.16.2007 @ 9:52 PM
blog bits This telecommuting job post from a Washington, D.C. firm who's "looking to build a

Leave a Comment