I'm Keyvan Nayyeri, a 25 years old Ph.D. student at
the Computer Science department of
the University of Texas at San Antonio.
I'm also
a Software Architect and Developer and previously held a B.Sc.
degree in Applied Mathematics.
This is my blog where I publish content about various topics specifically Programming Languages and Compilers, Software
Engineering and Programming.
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.
Dave Burke
Aug 16, 2007 9:12 PM
#
Dave Burke's Community Server Bits
Aug 16, 2007 9:23 PM
#
Community Blogs
Aug 16, 2007 9:52 PM
#
Leave a Comment