public void Terminate()
 {
     Messages.Clear();
     messageUIDS.Clear();
     Conversations.Clear();
     ConversationByCID.Clear();
     visibilityByConversationID.Clear();
     ConversationFilter = string.Empty;
 }
        public void GetAllConversations()
        {
            App.Current.Dispatcher.Invoke((Action) delegate

            {
                Conversations.Clear();
                ConversationByCID.Clear();
                CurrentConversation = null;
            });


            WebSocket.Instance.GetAllConversations();
        }
        public void ReceivedUserConversations(List <Conversation> conversations)
        {
            App.Current.Dispatcher.Invoke((Action) delegate

            {
                CurrentConversation = null;
                ConversationFilter  = string.Empty;
                Conversations.Clear();
                ConversationByCID.Clear();

                foreach (var conversation in conversations)
                {
                    AddConversationToView(conversation);
                }
            });
        }
        public void OnReceivedAllConversations(List <Conversation> conversations)
        {
            App.Current.Dispatcher.BeginInvoke((Action) delegate

            {
                CurrentConversation = null;
                Conversations.Clear();
                ConversationByCID.Clear();

                var filteredConverstions = conversations.Where(w => w.ConvName.ToLower().Contains(ConversationFilter.ToLower()));

                foreach (var conversation in filteredConverstions)
                {
                    AddConversationToView(conversation);
                }
            });
        }
        private void AddConversationToView(Conversation conversation)
        {
            if (ConversationByCID.ContainsKey(conversation.CID))
            {
                ConversationByCID[conversation.CID].UIDS = conversation.UIDS;
                if (conversation.Equals(CurrentConversation))
                {
                    CurrentConversation = ConversationByCID[conversation.CID];
                }
            }

            else
            {
                ConversationByCID.Add(conversation.CID, conversation);

                App.Current.Dispatcher.Invoke((Action) delegate

                {
                    Conversations.Add(conversation);
                });
            }
        }