//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.IO;
using System.Web.Caching;
using CommunityServer.Components;

namespace CommunityServer.Components {

    // *********************************************************************
    //  UserMessages
    //
    /// <summary>
    /// This class contains methods for sending and managing private messages
    /// between users
    /// </summary>
    // ***********************************************************************/
    public class UserMessages {

		public static void InvalidateMessageCount (int userID) 
		{
			string key = "usermessages-unread-count-" + userID.ToString();

			CSCache.Remove(key);
		}

		public static int UnreadMessagesCount (int userID) 
		{
			string key = "usermessages-unread-count-" + userID.ToString();

			if (CSCache.Get(key) == null) 
			{
				int unreadCount = 0;

				// Create Instance of the CommonDataProvider
				//
				CommonDataProvider dp = CommonDataProvider.Instance();

				unreadCount = dp.UnreadMessagesCount(userID);

				CSCache.Insert(key, unreadCount, 3600);
			}


			return (int) CSCache.Get(key);

		}

    }
}
