Пример #1
0
        public void ToPlainText_Should_Strip_Html()
        {
            string html  = "<b>Hello</b> world!";
            string plain = HtmlSanitizer.ToPlainText(html);

            Assert.AreEqual("Hello world!", plain);
        }
Пример #2
0
        void HandleNewContent(IChatHandler handler,AbstractChatContent content)
        {
            if (content is ChatContentTyping)
            {
                var typingContent = (ChatContentTyping)content;
                if (m_Handler is ChatHandler)
                {
                    var chatHandler = (ChatHandler)m_Handler;
                    if (!chatHandler.IsMucMessage)
                    {
                        string title = null;
                        if (typingContent.TypingState != TypingState.None && typingContent.TypingState != TypingState.Active)
                        {
                            title = String.Format("{0} ({1})",chatHandler.Account.GetDisplayName(chatHandler.Jid),typingContent.TypingState.ToString());
                        }
                        else
                        {
                            title = chatHandler.Account.GetDisplayName(chatHandler.Jid);
                        }
                        QApplication.Invoke(delegate {
                            Gui.TabbedChatsWindow.SetTabTitle(this,title);
                        });
                    }
                }
            }
            else
            {
                bool isSimilar = (!(content is ChatContentStatus)) && m_PreviousContent != null && content.IsSimilarToContent(m_PreviousContent);
                //bool replaceLast = m_PreviousContent is ChatContentStatus &&
                //	               content is ChatContentStatus &&
                //	               ((ChatContentStatus)m_PreviousContent).CoalescingKey == ((ChatContentStatus)content).CoalescingKey;
                bool replaceLast = m_PreviousContent is ChatContentTyping;

                m_PreviousContent = content;
                QApplication.Invoke(delegate {
                    m_ConversationWidget.AppendContent(content,isSimilar,false,replaceLast);

                    if (content is ChatContentMessage && !IsActive)
                    {
                        UrgencyHint = true;

                        if (m_Notification == null)
                        {
                            try {
                                string plainText = HtmlSanitizer.ToPlainText(((ChatContentMessage)content).MessageHtml);
                                // Only show notifications for MUC messages that contain your name.
                                if (m_Handler is ChatHandler || (m_Handler is MucHandler && plainText.Contains(((MucHandler)m_Handler).Room.Nickname)))
                                {
                                    if (m_Handler is MucHandler)
                                    {
                                        Gdk.Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource("internet-group-chat__32.png");
                                        string roomName   = ((MucHandler)m_Handler).Room.JID.Bare;
                                        m_Notification    = new Notification(String.Format("Message from {0} in {1}",content.SourceDisplayName,roomName),plainText,pixbuf);
                                    }
                                    else
                                    {
                                        // FIXME: Too much logic outside of AvatarManager.
                                        Gdk.Pixbuf pixbuf = null;
                                        string fileName   = AvatarManager.GetAvatarFileName(content.Source.BareJID);
                                        if (System.IO.File.Exists(fileName))
                                        {
                                            pixbuf = new Gdk.Pixbuf(fileName);
                                        }
                                        else
                                        {
                                            pixbuf = Gdk.Pixbuf.LoadFromResource("default-avatar.png");
                                        }
                                        m_Notification = new Notification(String.Format("Message from {0}",content.SourceDisplayName),plainText,pixbuf);
                                    }
                                    m_Notification.Show();
                                    m_Notification.Closed += delegate {
                                        m_Notification = null;
                                    };
                                }
                            } catch (Exception ex) {
                                Console.WriteLine("FAILED TO DISPLAY NOTIFICATION: " + ex);
                                m_Notification = null;
                            }
                        }
                    }

                    if (m_Handler is ChatHandler)
                    {
                        if (content is ChatContentMessage && (content.Source.Bare == ((ChatHandler)m_Handler).Jid.Bare))
                        {
                            // Select this resource so our replies go to it.
                            int i = m_ToComboBox.FindData(((ChatContentMessage)content).Source.Resource);
                            m_ToComboBox.CurrentIndex = (i > -1) ? i : 0;
                        }
                    }
                });
            }
        }