diff options
| author | Kevin Smith <git@kismith.co.uk> | 2010-04-05 21:55:55 (GMT) | 
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2010-04-05 21:55:55 (GMT) | 
| commit | 5e87304f8e31adeddcba41879057093e65047493 (patch) | |
| tree | 48fa139eeefce402ebcb4d30adb30f01196ad1d5 /Swift/Controllers/Chat/ChatsManager.cpp | |
| parent | a8ac900bfd39f36749b25d97b55f5a08a1020de5 (diff) | |
| download | swift-contrib-5e87304f8e31adeddcba41879057093e65047493.zip swift-contrib-5e87304f8e31adeddcba41879057093e65047493.tar.bz2 | |
Re-use Chat controllers when opening a new chat.
Resolves: #282
Diffstat (limited to 'Swift/Controllers/Chat/ChatsManager.cpp')
| -rw-r--r-- | Swift/Controllers/Chat/ChatsManager.cpp | 36 | 
1 files changed, 30 insertions, 6 deletions
| diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index 8c49cd6..db340ac 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -137,20 +137,44 @@ void ChatsManager::setEnabled(bool enabled) {  }  void ChatsManager::handleChatRequest(const String &contact) { -	ChatController* controller = getChatController(JID(contact)); +	ChatController* controller = getChatControllerOrFindAnother(JID(contact));  	controller->showChatWindow();  	controller->activateChatWindow();  } -ChatController* ChatsManager::getChatController(const JID &contact) { +ChatController* ChatsManager::getChatControllerOrFindAnother(const JID &contact) { +	ChatController* controller = getChatControllerIfExists(contact); +	if (!controller) { +		foreach (JIDChatControllerPair pair, chatControllers_) { +			if (pair.first.toBare() == contact.toBare()) { +				controller = pair.second; +				break; +			} +		} +	} +	return controller ? controller : createNewChatController(contact); +} + +ChatController* ChatsManager::createNewChatController(const JID& contact) { +	ChatController* controller = new ChatController(jid_, stanzaChannel_, iqRouter_, chatWindowFactory_, contact, nickResolver_, presenceOracle_, avatarManager_); +	chatControllers_[contact] = controller; +	controller->setAvailableServerFeatures(serverDiscoInfo_); +	return controller; +} + +ChatController* ChatsManager::getChatControllerOrCreate(const JID &contact) { +	ChatController* controller = getChatControllerIfExists(contact); +	return controller ? controller : createNewChatController(contact); +} + +ChatController* ChatsManager::getChatControllerIfExists(const JID &contact) {  	if (chatControllers_.find(contact) == chatControllers_.end()) { -		//Need to look for an unboud window to bind first +		//Need to look for an unbound window to bind first  		JID bare(contact.toBare());  		if (chatControllers_.find(bare) != chatControllers_.end()) {  			rebindControllerJID(bare, contact);  		} else { -			chatControllers_[contact] = new ChatController(jid_, stanzaChannel_, iqRouter_, chatWindowFactory_, contact, nickResolver_, presenceOracle_, avatarManager_); -			chatControllers_[contact]->setAvailableServerFeatures(serverDiscoInfo_); +			return NULL;  		}  	}  	return chatControllers_[contact]; @@ -197,7 +221,7 @@ void ChatsManager::handleIncomingMessage(boost::shared_ptr<Message> message) {  	//if not a mucroom  	eventController_->handleIncomingEvent(event); -	getChatController(jid)->handleIncomingMessage(event); +	getChatControllerOrCreate(jid)->handleIncomingMessage(event);  }  bool ChatsManager::isMUC(const JID& jid) const { | 
 Swift
 Swift