From 21e1e2d829690a127386071f173ffd8ad2e21db4 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Fri, 8 Jul 2011 20:16:47 +0100
Subject: Don't rebind chats when chatlistview updated


diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index 632ecd3..a2abbad 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -173,7 +173,7 @@ void ChatsManager::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) {
 
 ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const std::string& activity) {
 	int unreadCount = 0;
-	ChatController* controller = getChatControllerIfExists(jid);
+	ChatController* controller = getChatControllerIfExists(jid, false);
 	if (controller) {
 		unreadCount = controller->getUnreadCount();
 	}
@@ -345,7 +345,7 @@ ChatController* ChatsManager::getChatControllerOrCreate(const JID &contact) {
 	return controller ? controller : createNewChatController(contact);
 }
 
-ChatController* ChatsManager::getChatControllerIfExists(const JID &contact) {
+ChatController* ChatsManager::getChatControllerIfExists(const JID &contact, bool rebindIfNeeded) {
 	if (chatControllers_.find(contact) == chatControllers_.end()) {
 		if (mucRegistry_->isMUC(contact.toBare())) {
 			return NULL;
@@ -357,8 +357,13 @@ ChatController* ChatsManager::getChatControllerIfExists(const JID &contact) {
 		} else {
 			foreach (JIDChatControllerPair pair, chatControllers_) {
 				if (pair.first.toBare() == contact.toBare()) {
-					rebindControllerJID(pair.first, contact);
-					return chatControllers_[contact];
+					if (rebindIfNeeded) {
+						rebindControllerJID(pair.first, contact);
+						return chatControllers_[contact];
+					} else {
+						return pair.second;
+					}
+
 				}
 			}
 			return NULL;
diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h
index ccfdb3a..be6e575 100644
--- a/Swift/Controllers/Chat/ChatsManager.h
+++ b/Swift/Controllers/Chat/ChatsManager.h
@@ -79,7 +79,7 @@ namespace Swift {
 			ChatController* getChatControllerOrFindAnother(const JID &contact);
 			ChatController* createNewChatController(const JID &contact);
 			ChatController* getChatControllerOrCreate(const JID &contact);
-			ChatController* getChatControllerIfExists(const JID &contact);
+			ChatController* getChatControllerIfExists(const JID &contact, bool rebindIfNeeded = true);
 
 		private:
 			std::map<JID, MUCController*> mucControllers_;
-- 
cgit v0.10.2-6-g49f6