예제 #1
0
        public async void AddMessage(string text)
        {
            if (ServiceManager.IsConnected)
            {
                var reference = CurrentConversation;
                var id        = await ServiceManager.WriteMessage(text, reference.InterlocutorId);

                if (id != null)
                {
                    if (!Conversations.Contains(reference))
                    {
                        Conversations.Insert(0, reference);
                    }
                    else
                    {
                        Conversations.Move(Conversations.IndexOf(reference), 0);
                    }

                    reference.Messages.Add(new Message()
                    {
                        Content  = text,
                        IsAuthor = true,
                        Id       = id
                    });
                }

                _parent.MessagesListBox.ScrollIntoView(
                    reference.Messages[reference.Messages.Count - 1]);
            }
        }
        /// <summary>
        /// add content to the stream
        /// </summary>
        /// <param name="dest"></param>
        public void Add(String dest)
        {
            Conversation neo = new Conversation(_Server, name, dest);

            if (!Conversations.Contains(neo))
            {
                Conversations.Add(neo);
                neo.delete += new EventHandler <EventArgs>(neo_delete);
                neo.focus  += new EventHandler <EventArgs>(neo_focus);
                OnPropertyChanged("Conversations");
            }
        }
        /// <summary>
        ///  add content to the stream and create a chat
        /// </summary>
        /// <param name="dest"></param>
        /// <param name="content"></param>
        public void Add(String dest, String content)
        {
            Application.Current.Dispatcher.Invoke(new Action(delegate()
            {
                Conversation neo = new Conversation(_Server, name, dest, content);

                if (!Conversations.Contains(neo))
                {
                    Conversations.Add(neo);


                    neo.delete += new EventHandler <EventArgs>(neo_delete);
                    neo.focus  += new EventHandler <EventArgs>(neo_focus);
                    OnPropertyChanged("Conversations");
                }
                else
                {
                    Conversations.ElementAt(Conversations.IndexOf(neo)).addContent(content);
                }
            }), null);
        }