private void UpdateMessage(ReceiveMessageData receiveMessageData, ChatContext chatContext)
        {
            var message =
                chatContext.MsgList.FirstOrDefault(message => message.MessageId == receiveMessageData.MessageId);

            message.Message = receiveMessageData.Message;
        }
 private void Notify(ReceiveMessageData receiveMessageData)
 {
     foreach (var subscriber in _subscribers)
     {
         subscriber.OnMessage(receiveMessageData);
     }
 }
        private void UpdateChatContext(ReceiveMessageData receiveMessageData)
        {
            if (receiveMessageData.ReplyThreadId != -1)
            {
                var chatContext = _allMessages.FirstOrDefault(chatContext =>
                                                              chatContext.ThreadId == receiveMessageData.ReplyThreadId);
                switch (receiveMessageData.Event)
                {
                case MessageEvent.NewMessage:
                    Trace.WriteLine("[ChatContextServer] Event is NewMessage, Adding message to existing Thread");
                    chatContext.MsgList.Add(receiveMessageData);
                    chatContext.NumOfMessages++;
                    break;

                case MessageEvent.Star:
                    Trace.WriteLine("[ChatContextServer] Event is Star, Starring message in existing Thread");
                    StarMessage(receiveMessageData, chatContext);
                    break;

                case MessageEvent.Update:
                    Trace.WriteLine("[ChatContextServer] Event is Update, Updating message in existing Thread");
                    UpdateMessage(receiveMessageData, chatContext);
                    break;

                default:
                    Debug.Assert(false, "[ChatContextServer] Unkown Event");
                    return;
                }

                _contentDatabase.UpdateChatContext(chatContext.ThreadId, chatContext);
            }
            else
            {
                Trace.WriteLine("[ChatContextServer] Creating a new ChatContext and adding message to it");
                var chatContext = new ChatContext();
                chatContext.CreationTime  = receiveMessageData.SentTime;
                chatContext.NumOfMessages = 1;
                chatContext.MsgList       = new List <ReceiveMessageData>();
                chatContext.MsgList.Add(receiveMessageData);
                _contentDatabase.Store(chatContext);
                _allMessages.Add(chatContext);
            }
        }