CS: Private Message Notification for CS 2.1
The following changes will notify of Private Message posts and tell you how many new posts that you have:
CommunityServerBlogs(20)/Controls/DisplayUserWelcome.cs and
CommunityServerControls(20)/Skins/DisplayUserWelcome.cs:
Replace the
AttachChildControls() method with:
protected override void AttachChildControls()
{
int privateMessageCount = 0;
string url = "";
string anchorClass;
// Only process if the user is signed in
if (!csContext.Context.Request.IsAuthenticated)
return;
Control privateMessages = FindControl("PrivateMessages");
if (privateMessages != null)
{
if (Users.EnablePM(csContext.User))
{
privateMessageCount = UserMessages.UnreadMessagesCount(csContext.User.UserID);
if (privateMessageCount > 0)
{
url = string.Format(ResourceManager.GetString("PrivateMessage_Unread"), privateMessageCount);
anchorClass = " class=\"NewPrivateMessage\"";
}
else
{
url = string.Format(ResourceManager.GetString("PrivateMessages_Messages"), privateMessageCount);
anchorClass = string.Empty;
}
// Set URL
url = string.Format("<a{0} href=\"{1}\">{2}</a>", anchorClass, Globals.GetSiteUrls().UserPrivateMessages, url);
// Add to control tree
privateMessages.Controls.Add(new LiteralControl(" | " + url));
}
else
{
privateMessages.Visible = false;
}
}
}
CommunityServerComponents(20)/UserMessages.cs:
Change the line:
CSCache.Insert(key, unreadCount, 3600);
to read:
CSCache.Insert(key, unreadCount, 60);
You could change the timeout value to 1 second or some other value, but 60 seconds is probably a good setting as 1 minute is the new CS standard for running site processes.
CommunityServerWeb(20)/Languages/en-US/Resources.xml:
Find the following 2 lines:
<resource name = "PrivateMessages_Messages"> Inbox</resource>
<resource name = "PrivateMessage_Unread">Inbox ({0})</resource>
and replace then with:
<resource name = "PrivateMessages_Messages">Inbox</resource>
<resource name = "PrivateMessage_Unread">Inbox ({0})</resource>
In the
Common.css file of every theme:
After the section:
#welcome A, #welcome A:VISITED, #welcome A:ACTIVE, #welcome A:HOVER
{
<snip>
}
insert:
/* This is the class that will override parent styles when a user has messages */
#welcome A.NewPrivateMessage, #welcome A.NewPrivateMessage:VISITED, #welcome A.NewPrivateMessage:ACTIVE, #welcome A.NewPrivateMessage:HOVER
{
color: #FF0000;
}