Example #1
0
        // ---------------------------- FOR GUI USES ---------------------------- //
        /// <summary>
        /// This method takes user's choices of sorting and filters and updates the messages screen following this.
        /// </summary>
        /// <param name="Operations">The operation to make on certain list.</param>
        public void refresh(string[] filters, bool checkTime, ISort sorter, bool ascending)
        {
            _ascending = ascending;
            if (!(filters[0] == ""))
            {
                msgHandler.addGroupFilter(filters[0]);
            }
            if (!(filters[1] == ""))
            {
                msgHandler.addNicknameFilter(filters[1]);
            }
            if (!checkTime)
            {
                messages.Clear();
            }
            retrieveMessages(checkTime);
            messages = sorter.DoAction(messages);
            MessageConvertor       msgConvertor    = new MessageConvertor();
            List <ReadOnlyMessage> newReadOnlyList = new List <ReadOnlyMessage>();

            foreach (Message msg in messages)
            {
                ReadOnlyMessage roMsg = msgConvertor.convertToReadOnly(msg);
                newReadOnlyList.Add(roMsg);
            }
            messagesToPrint = newReadOnlyList;
        }
        /// <summary>
        /// this method receive a readOnlyMessage type message and returns it as a Message type
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public Message convertFromReadOnlyToMessage(ReadOnlyMessage msg)
        {
            string   body     = msg.body;
            string   nickname = msg.nickname;
            Guid     GUID     = msg.GUID;
            DateTime date     = msg.date;
            string   g_Id     = msg.g_ID;
            Message  message  = new Message(body, nickname, GUID, date, g_Id);

            return(message);
        }
        /// <summary>
        /// Convert IMessage message to an Message object.
        /// </summary>
        /// <param name="imsg"></param>
        /// <param name="charLimitPerMsg"></param>
        /// <returns>ReadOnlyMessage object</returns>
        public ReadOnlyMessage convertToReadOnly(Message msg)
        {
            if (msg == null)
            {
                return(null);
            }
            Guid            GUID     = msg.GUID;
            DateTime        date     = msg.date.ToLocalTime();
            string          nickname = msg.nickname;
            string          g_Id     = msg.g_ID;
            string          body     = msg.body;
            ReadOnlyMessage roMsg    = new ReadOnlyMessage(GUID, date, nickname, g_Id, body);

            return(roMsg);
        }
Example #4
0
 /// <summary>
 /// this method is called in case of editing exist message request is made by the user
 /// </summary>
 /// <param name="oldMessage">the message to edit</param>
 /// <param name="updatedBody">the updated content</param>
 public void update(ReadOnlyMessage oldMessage, string updatedBody)
 {
     try
     {
         //check its legal to edit this message
         if (!oldMessage.nickname.Equals(loggedinUser.nickName))
         {
             logger.logWarnMessage("Failed to edit a message which does not belong to the connected user");
         }
         else
         {
             _dateTime = DateTime.UtcNow;
             MessageConvertor mc      = new MessageConvertor();
             Message          message = mc.convertFromReadOnlyToMessage(oldMessage);
             messages.Remove(message);
             message.updateBody(updatedBody);
             message.updateDate(_dateTime);
             IMessage imsg = mc.convertToIMessage(message);
             msgHandler.updateMessage(imsg);//save the message into the storage file
             logger.logInfoMessage("The message were edited successfully");
         }
     }
     catch {}
 }