summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Chat/ChatMessageParser.cpp')
-rw-r--r--Swift/Controllers/Chat/ChatMessageParser.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/Swift/Controllers/Chat/ChatMessageParser.cpp b/Swift/Controllers/Chat/ChatMessageParser.cpp
index 09d93ac..5a608db 100644
--- a/Swift/Controllers/Chat/ChatMessageParser.cpp
+++ b/Swift/Controllers/Chat/ChatMessageParser.cpp
@@ -20,19 +20,19 @@
namespace Swift {
ChatMessageParser::ChatMessageParser(const std::map<std::string, std::string>& emoticons, HighlightRulesListPtr highlightRules, bool mucMode)
: emoticons_(emoticons), highlightRules_(highlightRules), mucMode_(mucMode) {
}
typedef std::pair<std::string, std::string> StringPair;
- ChatWindow::ChatMessage ChatMessageParser::parseMessageBody(const std::string& body, bool senderIsSelf) {
+ ChatWindow::ChatMessage ChatMessageParser::parseMessageBody(const std::string& body, const std::string& nick, bool senderIsSelf) {
ChatWindow::ChatMessage parsedMessage;
std::string remaining = body;
/* Parse one, URLs */
while (!remaining.empty()) {
bool found = false;
std::pair<std::vector<std::string>, size_t> links = Linkify::splitLink(remaining);
remaining = "";
for (size_t i = 0; i < links.first.size(); i++) {
const std::string& part = links.first[i];
@@ -51,19 +51,19 @@ namespace Swift {
}
}
}
/* do emoticon substitution */
parsedMessage = emoticonHighlight(parsedMessage);
if (!senderIsSelf) { /* do not highlight our own messsages */
/* do word-based color highlighting */
- parsedMessage = splitHighlight(parsedMessage);
+ parsedMessage = splitHighlight(parsedMessage, nick);
}
return parsedMessage;
}
ChatWindow::ChatMessage ChatMessageParser::emoticonHighlight(const ChatWindow::ChatMessage& message)
{
ChatWindow::ChatMessage parsedMessage = message;
@@ -132,30 +132,31 @@ namespace Swift {
newMessage.append(part);
}
}
parsedMessage = newMessage;
}
return parsedMessage;
}
- ChatWindow::ChatMessage ChatMessageParser::splitHighlight(const ChatWindow::ChatMessage& message)
+ ChatWindow::ChatMessage ChatMessageParser::splitHighlight(const ChatWindow::ChatMessage& message, const std::string& nick)
{
ChatWindow::ChatMessage parsedMessage = message;
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 */
}
- foreach(const boost::regex &regex, rule.getKeywordRegex()) {
+ 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;
if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
try {
boost::match_results<std::string::const_iterator> match;
const std::string& text = textPart->text;
std::string::const_iterator start = text.begin();
while (regex_search(start, text.end(), match, regex)) {