From b4fd267e414786efb11ca5492b7de308934d316c Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Wed, 19 Jan 2011 19:40:50 +0000
Subject: Only highlight in MUCs on complete-word nicknames.

Resolves: #738

diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 975a2d2..a447f60 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -7,6 +7,7 @@
 #include "Swift/Controllers/Chat/MUCController.h"
 
 #include <boost/bind.hpp>
+#include <boost/regex.hpp>
 
 #include "Swiften/Network/Timer.h"
 #include "Swiften/Network/TimerFactory.h"
@@ -226,7 +227,9 @@ JID MUCController::nickToJID(const String& nick) {
 }
 
 bool MUCController::messageTargetsMe(boost::shared_ptr<Message> message) {
-	return message->getBody().getLowerCase().contains(nick_.getLowerCase());
+	String stringRegexp(".*\\b" + nick_.getLowerCase() + "\\b.*");
+	boost::regex myRegexp(stringRegexp.getUTF8String());
+	return boost::regex_match(message->getBody().getLowerCase().getUTF8String(), myRegexp);
 }
 
 void MUCController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) {
diff --git a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
index fb3a0ee..21871cb 100644
--- a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
@@ -95,23 +95,44 @@ public:
 
 		message = Message::ref(new Message());
 		message->setFrom(JID(muc_->getJID().toString() + "/otherperson"));
-		message->setBody(nick_ + ": hi there");
+		message->setBody("basic " + nick_ + " test.");
 		message->setType(Message::Groupchat);
 		controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
 		CPPUNIT_ASSERT_EQUAL((size_t)1, eventController_->getEvents().size());
 
+		message = Message::ref(new Message());
+		message->setFrom(JID(muc_->getJID().toString() + "/otherperson"));
+		message->setBody(nick_ + ": hi there");
+		message->setType(Message::Groupchat);
+		controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+		CPPUNIT_ASSERT_EQUAL((size_t)2, eventController_->getEvents().size());
+
 		message->setFrom(JID(muc_->getJID().toString() + "/other"));
 		message->setBody("Hi there " + nick_);
 		message->setType(Message::Groupchat);
 		controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
-		CPPUNIT_ASSERT_EQUAL((size_t)2, eventController_->getEvents().size());
+		CPPUNIT_ASSERT_EQUAL((size_t)3, eventController_->getEvents().size());
 
 		message = Message::ref(new Message());
 		message->setFrom(JID(muc_->getJID().toString() + "/other2"));
-		message->setBody("Hi " + nick_.getLowerCase());
+		message->setBody("Hi " + nick_.getLowerCase() + ".");
 		message->setType(Message::Groupchat);
 		controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
-		CPPUNIT_ASSERT_EQUAL((size_t)3, eventController_->getEvents().size());
+		CPPUNIT_ASSERT_EQUAL((size_t)4, eventController_->getEvents().size());
+
+		message = Message::ref(new Message());
+		message->setFrom(JID(muc_->getJID().toString() + "/other3"));
+		message->setBody("Hi bert.");
+		message->setType(Message::Groupchat);
+		controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+		CPPUNIT_ASSERT_EQUAL((size_t)4, eventController_->getEvents().size());
+
+		message = Message::ref(new Message());
+		message->setFrom(JID(muc_->getJID().toString() + "/other2"));
+		message->setBody("Hi " + nick_.getLowerCase() + "ie.");
+		message->setType(Message::Groupchat);
+		controller_->handleIncomingMessage(MessageEvent::ref(new MessageEvent(message)));
+		CPPUNIT_ASSERT_EQUAL((size_t)4, eventController_->getEvents().size());
 	}
 
 	void testNotAddressedToSelf() {
-- 
cgit v0.10.2-6-g49f6