示例#1
0
        /// <summary>
        /// the function returns a list of messages, by specific sort, filter and order
        /// </summary>
        /// <param name="order">The wanted order of the list</param>
        /// <param name="sortAction">Sort</param>
        /// <param name="filterInfo">filter information</param>
        /// <returns>filtered and sorted messages list</returns>
        public List <GuiMessage> getMessages(int order, PresentationLayer.Action sortAction, string[] filterInfo)
        {
            bool update = false, filterChanged = false;

            // check if the sort or filter had changed, if they did, we update the current sort/filter
            if (sort != sortAction)
            {
                sort = sortAction;
            }
            // check if the filter was change
            for (int i = 0; i < filter.Length & !filterChanged; i++)
            {
                if (!filter[i].Equals(filterInfo[i]))
                {
                    filterChanged = true;
                }
            }

            // the list filterInfo contains - [0] - filter name, [1]- group id, [2]- nickname
            if (filterChanged)
            {
                update = true;
                if (filterInfo[0].Equals("NONE"))
                {
                    allMessages.filterByNone();
                }
                else if (filterInfo[0].Equals("ByGroup"))
                {
                    allMessages.FilterByGroup(filterInfo[1]);
                }
                else if (filterInfo[0].Equals("ByUser"))
                {
                    allMessages.FilterByUser(filterInfo[2], filterInfo[1]);
                }
                this.filter = filterInfo;
            }
            // if the filter/sort is changed, update the list of the presentation messages
            if (update)
            {
                updatePresMessages();
            }
            retrieveMessages();

            if (sort != null)
            {
                // ascending sort - defult sort
                sort.action(presMsgs);
                // if descending sort
                if (order == 1)
                {
                    presMsgs.Reverse();
                }
            }
            return(presMsgs);
        }
示例#2
0
        // constractors
        public ChatRoom(string url)
        {
            this.url      = url;
            this.currUser = null;
            presMsgs      = new List <GuiMessage>();
            sort          = new SortByTime();
            filter        = new string[3];
            filter[0]     = "NONE";
            filter[1]     = "";
            filter[2]     = "";
            // initialize the messages handler with a default filter - NONE
            HandlerFactory handler = new HandlerFactory();

            allMessages = handler.createMessageHandler();
            allUsers    = handler.createUserHandler();
            allMessages.filterByNone();
            updatePresMessages();
        }