What the heck is THIS nuglet about? Well, we're going to create a link in the forums discussion list to the most recent post made by a designated administrative user or role. Here's a great example from the World of Warcraft forum. It's a non-CS forum, but gives you an idea of what the link would look like. The Blizz link displays the most current authoritative post in the discussion.
I was asked today what would be involved to add this link to /forums/ShowForum.aspx in Community Server and whether the most recent administrator post information was readily available. The answer was no, this information is not readily available, but it does make for an interesting study in the Community Server Query, Thread and ThreadSet objects that generate a Forum Discussion list. This CS Nuglet then is a guide on adding a Most Recent Admin Forum Post link, looking at the process and objects along the way.
We begin in the CS.Discussions.Controls.ThreadView class and View-Threads.ascx. Here we populate our query based on the many filters and view options supported in Community Server Forums. The posts for the forum we retrieve are a ThreadSet object and retrieved from CS.Discussions.Components.Threads GetThreads(ForumThreadQuery query), where ForumThreadQuery inherits from the shared CS.Components.ThreadQuery object.
Here in the Discussions.Threads component our very cool CacheKey is created based on the current query object. The CacheKey stores our previously viewed ThreadSet for quick retrieval from the cache when we return to the list. Here's a before and after of creating that cacheKey with a screenshot (enlarge to view.)
Key goes in as
and comes out as
If our ThreadSet is not available in cache we pass our query object along to the ForumSqlDataProvider to retrieve a ThreadSet from GetThreads(ForumThreadQuery query) with the cs_Threads_GetThreadSet stored procedure. Our new ThreadSet will be complete when an ArrayList of Threads is added by a DataReader in the same GetThreads() method.
The CS.Discussion.Thread object contains everything a growing Discussion list needs to grow up healthy and strong, but it doesn't contain a MostRecentAdminPostID integer property. This is all that would be needed to generate a Most Recent Admin Forum Post url given Community Server's beefy Url Provider services. We do have a MostRecentPostID property, even a MostRecentPostAuthor string and MostRecentPostAuthorID int, but to add a link to the Most Recent Administrative Post, we'd need a MostRecentAdminPostID as well.
To finish up, given what we now know about threadsets, threads and the process of generating a discussions list, what would be needed to add a link to the most recent administrator or designated role post in a discussion thread? Not much. We would need to
1) add logic to the cs_Threads_GetThreadSet SQL stored procedure to return a postID of the most recent post based on our administrator/role criteria
2) add a MostRecentAdminPostID integer property to the Discussions Thread component object,
3) populate the MostRecentAdminPostID property from the Forums Data Provider PopulateThreadFromIDataReader() method, and
4) create and generate the hyperlink in the ThreadView.cs class and View-Threads.ascx controls