From 4f51ab844859e0784324b70751b3d06dfd84cfa5 Mon Sep 17 00:00:00 2001
From: Igor Borovkov <iborovkov@productengine.com>
Date: Wed, 13 Jan 2010 14:27:15 +0200
Subject: [PATCH] fixed EXT-3821 [BSI] New IMs are not added as tabs

--HG--
branch : product-engine
---
 indra/newview/llbottomtray.cpp         |  3 +
 indra/newview/llimfloater.cpp          | 76 ++++++++++++++------------
 indra/newview/llimfloater.h            |  4 ++
 indra/newview/llimfloatercontainer.cpp | 11 ++++
 indra/newview/llimfloatercontainer.h   |  6 +-
 5 files changed, 65 insertions(+), 35 deletions(-)

diff --git a/indra/newview/llbottomtray.cpp b/indra/newview/llbottomtray.cpp
index 8c90fffa0a5..c4de29e6adc 100644
--- a/indra/newview/llbottomtray.cpp
+++ b/indra/newview/llbottomtray.cpp
@@ -161,6 +161,9 @@ void LLBottomTray::sessionAdded(const LLUUID& session_id, const std::string& nam
 	{
 		chiclet->setIMSessionName(name);
 		chiclet->setOtherParticipantId(other_participant_id);
+		
+		LLIMFloater::onIMChicletCreated(session_id);
+
 	}
 	else
 	{
diff --git a/indra/newview/llimfloater.cpp b/indra/newview/llimfloater.cpp
index 02eb29eedd4..c52e749d647 100644
--- a/indra/newview/llimfloater.cpp
+++ b/indra/newview/llimfloater.cpp
@@ -361,35 +361,7 @@ LLIMFloater* LLIMFloater::show(const LLUUID& session_id)
 {
 	if (!gIMMgr->hasSession(session_id)) return NULL;
 
-	// we should make sure all related chiclets are in place when the session is a voice call
-	// chiclets come firts, then comes IM window
-	if (gIMMgr->isVoiceCall(session_id))
-	{
-		LLIMModel* im_model = LLIMModel::getInstance();
-		LLBottomTray* b_tray = LLBottomTray::getInstance();
-		
-		//*TODO hide that into Bottom tray
-		if (!b_tray->getChicletPanel()->findChiclet<LLChiclet>(session_id))
-		{
-			LLIMChiclet* chiclet = b_tray->createIMChiclet(session_id);
-			if(chiclet)
-			{
-				chiclet->setIMSessionName(im_model->getName(session_id));
-				chiclet->setOtherParticipantId(im_model->getOtherParticipantID(session_id));
-			}
-		}
-
-		LLIMWellWindow::getInstance()->addIMRow(session_id);
-	}
-		
-	bool not_existed = true;
-
-	if(isChatMultiTab())
-	{
-		LLIMFloater* target_floater = findInstance(session_id);
-		not_existed = NULL == target_floater;
-	}
-	else
+	if(!isChatMultiTab())
 	{
 		//hide all
 		LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("impanel");
@@ -404,19 +376,33 @@ LLIMFloater* LLIMFloater::show(const LLUUID& session_id)
 		}
 	}
 
-	LLIMFloater* floater = LLFloaterReg::showTypedInstance<LLIMFloater>("impanel", session_id);
+	bool exist = findInstance(session_id);
+
+	LLIMFloater* floater = getInstance(session_id);
+	if (!floater) return NULL;
 
 	if(isChatMultiTab())
 	{
+		LLIMFloaterContainer* floater_container = LLIMFloaterContainer::getInstance();
+
 		// do not add existed floaters to avoid adding torn off instances
-		if (not_existed)
+		if (!exist)
 		{
 			//		LLTabContainer::eInsertionPoint i_pt = user_initiated ? LLTabContainer::RIGHT_OF_CURRENT : LLTabContainer::END;
 			// TODO: mantipov: use LLTabContainer::RIGHT_OF_CURRENT if it exists
 			LLTabContainer::eInsertionPoint i_pt = LLTabContainer::END;
+			
+			if (floater_container)
+			{
+				floater_container->addFloater(floater, TRUE, i_pt);
+			}
+		}
 
-			LLIMFloaterContainer* floater_container = LLFloaterReg::showTypedInstance<LLIMFloaterContainer>("im_container");
-			floater_container->addFloater(floater, TRUE, i_pt);
+		if (floater_container)
+		{
+			//selecting the panel resets a chiclet's counter
+			floater_container->selectFloater(floater);
+			floater_container->setVisible(TRUE);
 		}
 	}
 	else
@@ -443,8 +429,8 @@ LLIMFloater* LLIMFloater::show(const LLUUID& session_id)
 		}
 
 		// window is positioned, now we can show it.
-		floater->setVisible(true);
 	}
+	floater->setVisible(TRUE);
 
 	return floater;
 }
@@ -538,6 +524,11 @@ LLIMFloater* LLIMFloater::findInstance(const LLUUID& session_id)
 	return LLFloaterReg::findTypedInstance<LLIMFloater>("impanel", session_id);
 }
 
+LLIMFloater* LLIMFloater::getInstance(const LLUUID& session_id)
+{
+	return LLFloaterReg::getTypedInstance<LLIMFloater>("impanel", session_id);
+}
+
 void LLIMFloater::sessionInitReplyReceived(const LLUUID& im_session_id)
 {
 	mSessionInitialized = true;
@@ -1016,3 +1007,20 @@ void LLIMFloater::sRemoveTypingIndicator(const LLSD& data)
 
 	floater->removeTypingIndicator();
 }
+
+void LLIMFloater::onIMChicletCreated( const LLUUID& session_id )
+{
+
+	if (isChatMultiTab())
+	{
+		LLIMFloaterContainer* im_box = LLIMFloaterContainer::getInstance();
+		if (!im_box) return;
+
+		if (LLIMFloater::findInstance(session_id)) return;
+
+		LLIMFloater* new_tab = LLIMFloater::getInstance(session_id);
+
+		im_box->addFloater(new_tab, FALSE, LLTabContainer::END);
+	}
+
+}
\ No newline at end of file
diff --git a/indra/newview/llimfloater.h b/indra/newview/llimfloater.h
index 87ccad1d34b..d9db385d06a 100644
--- a/indra/newview/llimfloater.h
+++ b/indra/newview/llimfloater.h
@@ -74,6 +74,8 @@ class LLIMFloater : public LLTransientDockableFloater
 
 	static LLIMFloater* findInstance(const LLUUID& session_id);
 
+	static LLIMFloater* getInstance(const LLUUID& session_id);
+
 	void sessionInitReplyReceived(const LLUUID& im_session_id);
 
 	// get new messages from LLIMModel
@@ -112,6 +114,8 @@ class LLIMFloater : public LLTransientDockableFloater
 	//used as a callback on receiving new IM message
 	static void sRemoveTypingIndicator(const LLSD& data);
 
+	static void onIMChicletCreated(const LLUUID& session_id);
+
 private:
 	// process focus events to set a currently active session
 	/* virtual */ void onFocusLost();
diff --git a/indra/newview/llimfloatercontainer.cpp b/indra/newview/llimfloatercontainer.cpp
index 2d7333f7e47..6cc985aef49 100644
--- a/indra/newview/llimfloatercontainer.cpp
+++ b/indra/newview/llimfloatercontainer.cpp
@@ -34,6 +34,7 @@
 #include "llviewerprecompiledheaders.h"
 
 #include "llimfloatercontainer.h"
+#include "llfloaterreg.h"
 
 //
 // LLIMFloaterContainer
@@ -93,4 +94,14 @@ void LLIMFloaterContainer::addFloater(LLFloater* floaterp,
 	}
 }
 
+LLIMFloaterContainer* LLIMFloaterContainer::findInstance()
+{
+	return LLFloaterReg::findTypedInstance<LLIMFloaterContainer>("im_container");
+}
+
+LLIMFloaterContainer* LLIMFloaterContainer::getInstance()
+{
+	return LLFloaterReg::getTypedInstance<LLIMFloaterContainer>("im_container");
+}
+
 // EOF
diff --git a/indra/newview/llimfloatercontainer.h b/indra/newview/llimfloatercontainer.h
index ead7cf47309..d4a542dfc22 100644
--- a/indra/newview/llimfloatercontainer.h
+++ b/indra/newview/llimfloatercontainer.h
@@ -52,7 +52,11 @@ class LLIMFloaterContainer : public LLMultiFloater
 								LLTabContainer::eInsertionPoint insertion_point = LLTabContainer::END);
 
 	static LLFloater* getCurrentVoiceFloater();
-	
+
+	static LLIMFloaterContainer* findInstance();
+
+	static LLIMFloaterContainer* getInstance();
+
 protected:
 	
 	LLFloater* mActiveVoiceFloater;
-- 
GitLab