Is there a control or class to get the latest messages or count after a user logs in?

I'd like to implement something similar to the top notifications bars on Stack Overflow, where the user is told if they have new messages after they log in. E.g.

  1. User logs in
  2. Somewhere on the screen after being logged in, a message says: "Welcome Pete, you have 3 new messages. Go to your inbox."

Is there either a control or a class that I can use to accomplish something like this?

  • Does anyone know anything about this?

  • Yes there is.  Showing the number of unread conversations is something we do out of the box - if you take a look in the Utility\HeaderFragments\Core\UserWelcome.ascx file you should see an example of how to do this.

  • In reply to Alex Crome:

    Thanks Alex. Is there a way to do this via the client API instead of using controls? I'd really prefer to have the exact count in my code-behind for other uses.

  • In reply to Mark Ursino:

    Hi. I'm just trying to see if anyone is aware of a way to get the unread message count using the C# client API. I've been looking in CommunityServer.Messages but I haven't found anything yet.

  • In reply to Mark Ursino:

    Howdy Mark,

    You might find your answer in something like this:

    ConversationQuery query = new ConversationQuery();

    query.ReadStatus = ConversationReadStatus.Unread;

    ...whatever other query stuff you need...

    Messages.Controls.ConversationQuery queryRunner = new Messages.Controls.ConversationQuery();

    queryRunner.QueryImplementation.GetQueryResults<Conversation(query, out int);

    Hope that helps!
  • In reply to Blake "Howdy" Smith:

    Hi Blake,
    I tried what you gave me an I keep getting a "Object reference not set to an instance of an object." on the queryRunner.QueryImplementation.GetQueryResults line:

    CommunityServer.Messages.ConversationQuery query = new CommunityServer.Messages.ConversationQuery();
    int totalResults;

    query.ReadStatus = CommunityServer.Messages.ConversationReadStatus.Unread;
    query.UserId = 2100; // test admin for now

    CommunityServer.Messages.Controls.ConversationQuery queryRunner = new CommunityServer.Messages.Controls.ConversationQuery();

    List<CommunityServer.Messages.Conversation> convos = queryRunner.QueryImplementation.GetQueryResults<CommunityServer.Messages.Conversation>(query, out totalResults);

    Response.Write(convos.Count); // doesn't work
    Response.Write(totalResults); // also doesn't work

    Any thoughts? I hope I have the correct namespaces.

  • In reply to Mark Ursino:

    Yea, you have the right namespaces, guess that way won't work.  My research hasn't found any way to do it in code yet, the control Alex mentioned is all I've seen.  I'll take a deeper look when I get some free time.

  • In reply to Blake "Howdy" Smith:

    Hi Blake,

    I appreciate the time you're taking looking into it. I have it working right now on the front-end but I'd prefer to be it via code-behind since I use it in a few other places. For now, my solution was to create a UC that outputs just the number of unread messages, nothing else:


    <CSMessage:ConversationList ID="ConversationList" runat="server">
        <QueryOverrides runat="server" PageSize="1" ReadStatus="Unread" PagerID="UnreadPager" />
            <CSControl:ControlData ID="ControlData1" runat="server" ControlId="UnreadPager" Property="TotalRecords" Text="{0}" />
    <CSControl:Pager ID="UnreadPager" runat="server" Visible="false" />

    So anywhere I need the #, I just call this control on the front-end. Do you see any performance issues with this? Should I OutputCache my control? I'm just afraid so many calls to this for a user will bog the system down. I have a panel at the top of my page that pops down with jQuery and shows your unread message count. It ends up appearing on most of the pages because its a collapsed panel that the user has the ability to flip on. Thanks again and if you find anything with code, please share!