diff options
Diffstat (limited to 'Swift/Controllers/HighlightRule.cpp')
-rw-r--r-- | Swift/Controllers/HighlightRule.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Swift/Controllers/HighlightRule.cpp b/Swift/Controllers/HighlightRule.cpp index 40b7560..021e15d 100644 --- a/Swift/Controllers/HighlightRule.cpp +++ b/Swift/Controllers/HighlightRule.cpp @@ -7,19 +7,21 @@ /* * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ +#include <Swift/Controllers/HighlightRule.h> + #include <algorithm> + #include <boost/algorithm/string.hpp> #include <boost/lambda/lambda.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/Base/Regex.h> -#include <Swift/Controllers/HighlightRule.h> +#include <Swiften/Base/foreach.h> namespace Swift { HighlightRule::HighlightRule() : nickIsKeyword_(false) , matchCase_(false) @@ -66,16 +68,27 @@ bool HighlightRule::isMatch(const std::string& body, const std::string& sender, { if ((messageType == HighlightRule::ChatMessage && matchChat_) || (messageType == HighlightRule::MUCMessage && matchMUC_)) { bool matchesKeyword = keywords_.empty() && (nick.empty() || !nickIsKeyword_); bool matchesSender = senders_.empty(); - if (!matchesKeyword && nickIsKeyword_ && !nick.empty()) { - if (boost::regex_search(body, regexFromString(nick))) { + if (!matchesKeyword) { + // check if the nickname matches + if (nickIsKeyword_ && !nick.empty() && boost::regex_search(body, regexFromString(nick))) { matchesKeyword = true; } + + // check if a keyword matches + if (!matchesKeyword && !keywords_.empty()) { + foreach (const boost::regex &keyword, keywordRegex_) { + if (boost::regex_search(body, keyword)) { + matchesKeyword = true; + break; + } + } + } } foreach (const boost::regex & rx, senderRegex_) { if (boost::regex_search(sender, rx)) { matchesSender = true; break; |