From b37f501a87f91851d8b2d9904d3910e95def1abc Mon Sep 17 00:00:00 2001
From: Gilbert Gonzales <gilbert@lindenlab.com>
Date: Mon, 1 Apr 2013 15:36:05 -0700
Subject: [PATCH] CHUI-796 (User doesn't get all messages in 'do not disturb'
 mode): Now when a conversation is focused by clicking on it's line item,
 selecting a torn off floater or unminimized a torn off floater the stored
 notifications for that conversation will be removed.

---
 indra/newview/llfloaterimcontainer.cpp  | 62 +++++++++++++++++++------
 indra/newview/llfloaterimcontainer.h    |  1 +
 indra/newview/llfloaterimnearbychat.cpp |  2 +-
 indra/newview/llfloaterimsession.cpp    | 30 ++++++++++++
 indra/newview/llfloaterimsession.h      |  2 +
 5 files changed, 82 insertions(+), 15 deletions(-)

diff --git a/indra/newview/llfloaterimcontainer.cpp b/indra/newview/llfloaterimcontainer.cpp
index 7296ec3ceda..58817485fb5 100644
--- a/indra/newview/llfloaterimcontainer.cpp
+++ b/indra/newview/llfloaterimcontainer.cpp
@@ -585,6 +585,28 @@ void LLFloaterIMContainer::returnFloaterToHost()
 	floater->onTearOffClicked();
 }
 
+void LLFloaterIMContainer::setMinimized(BOOL b)
+{
+	bool was_minimized = isMinimized();
+	LLMultiFloater::setMinimized(b);
+
+	//Switching from minimized to un-minimized
+	if(was_minimized && !b)
+	{
+		LLFloaterIMSessionTab* session_floater = LLFloaterIMSessionTab::findConversation(mSelectedSession);
+
+		if(session_floater && !session_floater->isTornOff())
+		{
+			//When in DND mode, remove stored IM notifications
+			//Nearby chat (Null) IMs are not stored while in DND mode, so can ignore removal
+			if(gAgent.isDoNotDisturb() && mSelectedSession.notNull())
+			{
+				LLDoNotDisturbNotificationStorage::getInstance()->removeNotification(LLDoNotDisturbNotificationStorage::toastName, mSelectedSession);
+			}
+		}
+	}
+}
+
 void LLFloaterIMContainer::setVisible(BOOL visible)
 {	LLFloaterIMNearbyChat* nearby_chat;
 	if (visible)
@@ -597,10 +619,21 @@ void LLFloaterIMContainer::setVisible(BOOL visible)
 			// *TODO: find a way to move this to XML as a default panel or something like that
 			LLSD name("nearby_chat");
 			LLFloaterReg::toggleInstanceOrBringToFront(name);
-            setSelectedSession(LLUUID(NULL));
+            selectConversationPair(LLUUID(NULL), false, false);
 		}
 		openNearbyChat();
-        selectConversationPair(getSelectedSession(), false, false);
+		flashConversationItemWidget(mSelectedSession,false);
+
+		LLFloaterIMSessionTab* session_floater = LLFloaterIMSessionTab::findConversation(mSelectedSession);
+		if(session_floater && !session_floater->isMinimized())
+		{
+			//When in DND mode, remove stored IM notifications
+			//Nearby chat (Null) IMs are not stored while in DND mode, so can ignore removal
+			if(gAgent.isDoNotDisturb() && mSelectedSession.notNull())
+			{
+				LLDoNotDisturbNotificationStorage::getInstance()->removeNotification(LLDoNotDisturbNotificationStorage::toastName, mSelectedSession);
+			}
+		}
 	}
 
 	nearby_chat = LLFloaterReg::findTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
@@ -1389,13 +1422,6 @@ BOOL LLFloaterIMContainer::selectConversationPair(const LLUUID& session_id, bool
     		widget->getParentFolder()->setSelection(widget, FALSE, FALSE);
     		mConversationsRoot->scrollToShowSelection();
     	}
-
-        //When in DND mode, remove stored IM notifications
-        //Nearby chat (Null) IMs are not stored while in DND mode, so can ignore removal
-        if(gAgent.isDoNotDisturb() && session_id.notNull())
-        {
-            LLDoNotDisturbNotificationStorage::getInstance()->removeNotification(LLDoNotDisturbNotificationStorage::toastName, session_id);
-        }
     }
 
     /* floater processing */
@@ -1420,14 +1446,19 @@ BOOL LLFloaterIMContainer::selectConversationPair(const LLUUID& session_id, bool
 			{
 				showStub(true);
 			}
+
+			//When in DND mode, remove stored IM notifications
+			//Nearby chat (Null) IMs are not stored while in DND mode, so can ignore removal
+			if(gAgent.isDoNotDisturb() && session_id.notNull())
+			{
+				LLDoNotDisturbNotificationStorage::getInstance()->removeNotification(LLDoNotDisturbNotificationStorage::toastName, session_id);
+			}
 		}
 
 		// Set the focus on the selected floater
-		if (!session_floater->hasFocus())
+		if (!session_floater->hasFocus() && !session_floater->isMinimized())
 		{
-			BOOL is_minimized = session_floater->isMinimized();
 			session_floater->setFocus(focus_floater);
-			session_floater->setMinimized(is_minimized);
 		}
 	}
 	flashConversationItemWidget(session_id,false);
@@ -1986,8 +2017,11 @@ void LLFloaterIMContainer::closeFloater(bool app_quitting/* = false*/)
 {
 	// Always unminimize before trying to close.
 	// Most of the time the user will never see this state.
-	setMinimized(FALSE);
-
+	if(isMinimized())
+	{
+		LLMultiFloater::setMinimized(FALSE);
+	}
+	
 	LLFloater::closeFloater(app_quitting);
 }
 
diff --git a/indra/newview/llfloaterimcontainer.h b/indra/newview/llfloaterimcontainer.h
index 52b672241f6..e39d20ec358 100644
--- a/indra/newview/llfloaterimcontainer.h
+++ b/indra/newview/llfloaterimcontainer.h
@@ -59,6 +59,7 @@ class LLFloaterIMContainer
 	/*virtual*/ BOOL postBuild();
 	/*virtual*/ void onOpen(const LLSD& key);
 	/*virtual*/ void draw();
+	/*virtual*/ void setMinimized(BOOL b);
 	/*virtual*/ void setVisible(BOOL visible);
 	/*virtual*/ void setVisibleAndFrontmost(BOOL take_focus=TRUE, const LLSD& key = LLSD());
 	/*virtual*/ void updateResizeLimits();
diff --git a/indra/newview/llfloaterimnearbychat.cpp b/indra/newview/llfloaterimnearbychat.cpp
index 56b0c15cb9e..49f36a2f321 100644
--- a/indra/newview/llfloaterimnearbychat.cpp
+++ b/indra/newview/llfloaterimnearbychat.cpp
@@ -328,7 +328,7 @@ void LLFloaterIMNearbyChat::onChatFontChange(LLFontGL* fontp)
 void LLFloaterIMNearbyChat::show()
 {
 		openFloater(getKey());
-	}
+}
 
 bool LLFloaterIMNearbyChat::isChatVisible() const
 {
diff --git a/indra/newview/llfloaterimsession.cpp b/indra/newview/llfloaterimsession.cpp
index 6d5145f205f..edc25a7d7ec 100644
--- a/indra/newview/llfloaterimsession.cpp
+++ b/indra/newview/llfloaterimsession.cpp
@@ -39,6 +39,7 @@
 #include "llchannelmanager.h"
 #include "llchiclet.h"
 #include "llchicletbar.h"
+#include "lldonotdisturbnotificationstorage.h"
 #include "llfloaterreg.h"
 #include "llfloateravatarpicker.h"
 #include "llfloaterimcontainer.h" // to replace separate IM Floaters with multifloater container
@@ -645,6 +646,23 @@ void LLFloaterIMSession::setDocked(bool docked, bool pop_on_undock)
 	}
 }
 
+void LLFloaterIMSession::setMinimized(BOOL b)
+{
+	bool wasMinimized = isMinimized();
+	LLFloaterIMSessionTab::setMinimized(b);
+
+	//Switching from minimized state to un-minimized state
+	if(wasMinimized && !b)
+	{
+		//When in DND mode, remove stored IM notifications
+		//Nearby chat (Null) IMs are not stored while in DND mode, so can ignore removal
+		if(gAgent.isDoNotDisturb())
+		{
+			LLDoNotDisturbNotificationStorage::getInstance()->removeNotification(LLDoNotDisturbNotificationStorage::toastName, mSessionID);
+		}
+	}
+}
+
 void LLFloaterIMSession::setVisible(BOOL visible)
 {
 	LLNotificationsUI::LLScreenChannel* channel = static_cast<LLNotificationsUI::LLScreenChannel*>
@@ -713,6 +731,18 @@ BOOL LLFloaterIMSession::getVisible()
 	return visible;
 }
 
+void LLFloaterIMSession::setFocus(BOOL focus)
+{
+	LLFloaterIMSessionTab::setFocus(focus);
+
+	//When in DND mode, remove stored IM notifications
+	//Nearby chat (Null) IMs are not stored while in DND mode, so can ignore removal
+	if(focus && gAgent.isDoNotDisturb())
+	{
+		LLDoNotDisturbNotificationStorage::getInstance()->removeNotification(LLDoNotDisturbNotificationStorage::toastName, mSessionID);
+	}
+}
+
 //static
 bool LLFloaterIMSession::toggle(const LLUUID& session_id)
 {
diff --git a/indra/newview/llfloaterimsession.h b/indra/newview/llfloaterimsession.h
index cb330bca0f2..a0e0171b344 100644
--- a/indra/newview/llfloaterimsession.h
+++ b/indra/newview/llfloaterimsession.h
@@ -65,8 +65,10 @@ class LLFloaterIMSession
 
 	// LLView overrides
 	/*virtual*/ BOOL postBuild();
+	/*virtual*/ void setMinimized(BOOL b);
 	/*virtual*/ void setVisible(BOOL visible);
 	/*virtual*/ BOOL getVisible();
+	/*virtual*/ void setFocus(BOOL focus);
 	// Check typing timeout timer.
 
 	/*virtual*/ void draw();
-- 
GitLab