From f60d331a3e32eff632a9af3b7bd5fc1c1811365f Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Sat, 28 Apr 2012 12:50:36 +0100
Subject: Only open chat windows when there's something to be displayed.

Resolves: #1009

diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index b0aef95..da96603 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -628,7 +628,15 @@ void ChatsManager::handleIncomingMessage(boost::shared_ptr<Message> message) {
 	}
 	
 	//if not a mucroom
-	getChatControllerOrCreate(jid)->handleIncomingMessage(event);
+	if (!event->isReadable() && !isInvite && !isMediatedInvite) {
+		/* Only route such messages if a window exists, don't open new windows for them.*/
+		ChatController* controller = getChatControllerIfExists(jid);
+		if (controller) {
+			controller->handleIncomingMessage(event);
+		}
+	} else {
+		getChatControllerOrCreate(jid)->handleIncomingMessage(event);
+	}
 }
 
 void ChatsManager::handleMUCSelectedAfterSearch(const JID& muc) {
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index bbfb22f..3d2db7d 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -433,6 +433,7 @@ private:
 		boost::shared_ptr<Message> message = boost::make_shared<Message>();
 		message->setFrom(from);
 		message->setID(id);
+		message->setBody("This will cause the window to open");
 		message->addPayload(boost::make_shared<DeliveryReceiptRequest>());
 		return message;
 	}
-- 
cgit v0.10.2-6-g49f6