diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/ChatMessageParser.cpp | 4 | ||||
-rw-r--r-- | Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp | 15 |
2 files changed, 16 insertions, 3 deletions
diff --git a/Swift/Controllers/Chat/ChatMessageParser.cpp b/Swift/Controllers/Chat/ChatMessageParser.cpp index fe61724..666ec2f 100644 --- a/Swift/Controllers/Chat/ChatMessageParser.cpp +++ b/Swift/Controllers/Chat/ChatMessageParser.cpp @@ -1,8 +1,8 @@ /* - * Copyright (c) 2013-2014 Isode Limited. + * Copyright (c) 2013-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/Controllers/Chat/ChatMessageParser.h> @@ -145,12 +145,14 @@ namespace Swift { for (size_t i = 0; i < highlightRules_->getSize(); ++i) { const HighlightRule& rule = highlightRules_->getRule(i); if (rule.getMatchMUC() && !mucMode_) { continue; /* this rule only applies to MUC's, and this is a CHAT */ } else if (rule.getMatchChat() && mucMode_) { continue; /* this rule only applies to CHAT's, and this is a MUC */ + } else if (rule.getAction().getTextBackground().empty() && rule.getAction().getTextColor().empty()) { + continue; /* do not try to highlight text, if no highlight color is specified */ } const std::vector<boost::regex> keywordRegex = rule.getKeywordRegex(nick); foreach(const boost::regex& regex, keywordRegex) { ChatWindow::ChatMessage newMessage; foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, parsedMessage.getParts()) { boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart; diff --git a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp index 1192c8f..1b92bb6 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp @@ -1,8 +1,8 @@ /* - * Copyright (c) 2013-2014 Isode Limited. + * Copyright (c) 2013-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> @@ -17,12 +17,13 @@ class ChatMessageParserTest : public CppUnit::TestFixture { CPPUNIT_TEST(testFullBody); CPPUNIT_TEST(testOneEmoticon); CPPUNIT_TEST(testBareEmoticon); CPPUNIT_TEST(testHiddenEmoticon); CPPUNIT_TEST(testEndlineEmoticon); CPPUNIT_TEST(testBoundedEmoticons); + CPPUNIT_TEST(testNoColourNoHighlight); CPPUNIT_TEST_SUITE_END(); public: void setUp() { smile1_ = ":)"; smile1Path_ = "/blah/smile1.png"; @@ -64,12 +65,13 @@ public: std::vector<std::string> keywords; keywords.push_back(keyword); rule.setKeywords(keywords); rule.setMatchCase(matchCase); rule.setMatchWholeWords(matchWholeWord); rule.setMatchChat(true); + rule.getAction().setTextBackground("white"); return rule; } static const HighlightRulesListPtr ruleListFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord) { boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>(); @@ -82,19 +84,22 @@ public: boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>(); list->addRule(rule1); list->addRule(rule2); return list; } - static HighlightRulesListPtr ruleListWithNickHighlight() + static HighlightRulesListPtr ruleListWithNickHighlight(bool withHighlightColour = true) { HighlightRule rule; rule.setMatchChat(true); rule.setNickIsKeyword(true); rule.setMatchCase(true); rule.setMatchWholeWords(true); + if (withHighlightColour) { + rule.getAction().setTextBackground("white"); + } boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>(); list->addRule(rule); return list; } void testFullBody() { @@ -253,12 +258,18 @@ public: ChatWindow::ChatMessage result = testling.parseMessageBody("(Like this :))"); assertText(result, 0, "(Like this "); assertEmoticon(result, 1, smile1_, smile1Path_); assertText(result, 2, ")"); } + void testNoColourNoHighlight() { + ChatMessageParser testling(emoticons_, ruleListWithNickHighlight(false)); + ChatWindow::ChatMessage result = testling.parseMessageBody("Alice", "Alice"); + assertText(result, 0, "Alice"); + } + private: std::map<std::string, std::string> emoticons_; std::string smile1_; std::string smile1Path_; std::string smile2_; std::string smile2Path_; |