Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChatViewModel" /> class
        /// </summary>
        /// <param name="container"></param>
        /// <param name="chat"></param>
        public ChatViewModel(XmppChat chat)
            : base()
        {
            this.chat               = chat;
            // this.emoticonPackage    = this.ResolveEmoticonPackage();

            this.conversation           = new FlowDocument();
            this.chat.ChatClosed        += new EventHandler(chat_ChatClosed);
            this.chat.ReceivedMessage   += new EventHandler(chat_ReceivedMessage);

            this.NotifyPropertyChanged(() => Contact);

            this.ShowMessages();
        }
Beispiel #2
0
 private void chat_ChatClosed(object sender, EventArgs e)
 {
     // Unbind event handlers
     this.chat.ChatClosed        -= new EventHandler(chat_ChatClosed);
     this.chat.ReceivedMessage   -= new EventHandler(chat_ReceivedMessage);
     this.chat                   = null;
 }
Beispiel #3
0
        /// <summary>
        /// Opens a new chat view for the given chat instance
        /// </summary>
        /// <param name="chat">A <see cref="XmppChat"/> instance</param>
        public void OpenChatView(XmppChat chat, bool activate)
        {
            this.Dispatcher.BeginInvoke
            (
                DispatcherPriority.Normal,
                new ThreadStart
                (
                    delegate
                    {
                        lock (SyncObject)
                        {
                            if (!activate)
                            {
                                ChatViewModel viewModel = new ChatViewModel(chat);
                                ChatView view = new ChatView();

                                view.DataContext = viewModel;

                                PivotItem chatViewItem = new PivotItem();

                                chatViewItem.HorizontalAlignment    = HorizontalAlignment.Stretch;
                                chatViewItem.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                                chatViewItem.Header                 = chat.Contact.DisplayName;
                                chatViewItem.Content                = view;

                                this.chatViews.Add(chat.Contact.ContactId.BareIdentifier, chatViewItem);

                                this.container.Items.Add(chatViewItem);
                                this.container.Invalidate();
                                this.container.SelectedItem = chatViewItem;
                            }
                            else
                            {
                                this.container.SelectedItem = this.chatViews[chat.Contact.ContactId.BareIdentifier];
                            }
                        }
                    }
                )
            );
        }
Beispiel #4
0
        /// <summary>
        /// Creates the chat.
        /// </summary>
        /// <param name="contactId">The contact id.</param>
        /// <returns></returns>
        public XmppChat CreateChat(XmppJid contactId)
        {
            this.CheckSessionState();

            XmppChat chat = null;

            lock (this.syncObject)
            {
                if (!this.chats.ContainsKey(contactId.BareIdentifier))
                {
                    chat = new XmppChat(this, this.Roster[contactId.BareIdentifier]);
                    this.chats.Add(contactId.BareIdentifier, chat);

                    chat.ChatClosed += new EventHandler(OnChatClosed);
                }
                else
                {
                    chat = this.chats[contactId.BareIdentifier];
                }
            }

            return chat;
        }
Beispiel #5
0
 /// <summary>
 /// Opens a new chat view for the given chat instance
 /// </summary>
 /// <param name="chat">A <see cref="XmppChat"/> instance</param>
 public void OpenChatView(XmppChat chat)
 {
     this.OpenChatView(chat, false);
 }