From fdf774f51fd24bb62d1e1fc580bd04df4547b9f8 Mon Sep 17 00:00:00 2001
From: Gilbert Gonzales <gilbert@lindenlab.com>
Date: Thu, 17 Jan 2013 13:52:51 -0800
Subject: CHUI-685 Problem: The notifications .xml file was cleared upon exit
 because removeIMNotification was being called and deleting inventory offers
 becaus they did not have a session id. Resolution: Now check to make sure
 that removeIMNotification only removes IMs (IMToast).

---
 .../newview/lldonotdisturbnotificationstorage.cpp  | 62 ++++++++++++----------
 indra/newview/lldonotdisturbnotificationstorage.h  |  3 --
 indra/newview/llfloaterimcontainer.cpp             | 16 +++---
 3 files changed, 40 insertions(+), 41 deletions(-)

diff --git a/indra/newview/lldonotdisturbnotificationstorage.cpp b/indra/newview/lldonotdisturbnotificationstorage.cpp
index 42b455c1ce..5bea7d41f6 100644
--- a/indra/newview/lldonotdisturbnotificationstorage.cpp
+++ b/indra/newview/lldonotdisturbnotificationstorage.cpp
@@ -43,15 +43,16 @@
 #include "lluuid.h"
 
 static const F32 DND_TIMER = 3.0;
+const std::string toastName = "IMToast";
 
 LLDoNotDisturbNotificationStorageTimer::LLDoNotDisturbNotificationStorageTimer() : LLEventTimer(DND_TIMER)
 {
-    mEventTimer.start();
+    //mEventTimer.start();
 }
 
 LLDoNotDisturbNotificationStorageTimer::~LLDoNotDisturbNotificationStorageTimer()
 {
-    mEventTimer.stop();
+    //mEventTimer.stop();
 }
 
 BOOL LLDoNotDisturbNotificationStorageTimer::tick()
@@ -152,27 +153,27 @@ void LLDoNotDisturbNotificationStorage::loadNotifications()
         std::string notificationName = notification_params["name"];
         LLNotificationPtr notification = instance.find(notificationID);
 
-        if(notificationName == "IMToast")
+        if(notificationName == toastName)
         {
             imToastExists = true;
         }
 
         //New notification needs to be added
-            notification = (LLNotificationPtr) new LLNotification(notification_params.with("is_dnd", true));
-			LLNotificationResponderInterface* responder = createResponder(notification_params["responder_sd"]["responder_type"], notification_params["responder_sd"]);
-			if (responder == NULL)
-			{
-				LL_WARNS("LLDoNotDisturbNotificationStorage") << "cannot create responder for notification of type '"
-					<< notification->getType() << "'" << LL_ENDL;
-			}
-			else
-			{
-				LLNotificationResponderPtr responderPtr(responder);
-				notification->setResponseFunctor(responderPtr);
-			}
-			
-			instance.add(notification);
+        notification = (LLNotificationPtr) new LLNotification(notification_params.with("is_dnd", true));
+		LLNotificationResponderInterface* responder = createResponder(notification_params["responder_sd"]["responder_type"], notification_params["responder_sd"]);
+		if (responder == NULL)
+		{
+			LL_WARNS("LLDoNotDisturbNotificationStorage") << "cannot create responder for notification of type '"
+				<< notification->getType() << "'" << LL_ENDL;
+		}
+		else
+		{
+			LLNotificationResponderPtr responderPtr(responder);
+			notification->setResponseFunctor(responderPtr);
 		}
+			
+		instance.add(notification);
+	}
 
     if(imToastExists)
     {
@@ -200,7 +201,7 @@ void LLDoNotDisturbNotificationStorage::updateNotifications()
         LLNotificationPtr notification = it->second;
         std::string notificationName = notification->getName();
 
-        if(notificationName == "IMToast")
+        if(notificationName == toastName)
         {
             imToastExists = true;
         }
@@ -221,9 +222,9 @@ void LLDoNotDisturbNotificationStorage::updateNotifications()
     //When exit DND mode, write empty notifications file
     if(commChannel->getHistorySize())
     {
-	commChannel->clearHistory();
-	saveNotifications();
-}
+	    commChannel->clearHistory();
+	    saveNotifications();
+    }
 }
 
 LLNotificationChannelPtr LLDoNotDisturbNotificationStorage::getCommunicationChannel() const
@@ -241,6 +242,7 @@ void LLDoNotDisturbNotificationStorage::removeIMNotification(const LLUUID& sessi
     LLNotificationPtr notification;
     LLSD substitutions;
     LLUUID notificationSessionID;
+    std::string notificationName;
     LLCommunicationChannel::history_list_t::iterator it;
     std::vector<LLCommunicationChannel::history_list_t::iterator> itemsToRemove;
 
@@ -252,8 +254,10 @@ void LLDoNotDisturbNotificationStorage::removeIMNotification(const LLUUID& sessi
         notification = it->second;
         substitutions = notification->getSubstitutions();
         notificationSessionID = substitutions["SESSION_ID"].asUUID();
+        notificationName = notification->getName();
 
-        if(session_id == notificationSessionID)
+        if(notificationName == toastName
+            && session_id == notificationSessionID)
         {
             itemsToRemove.push_back(it);
         }
@@ -263,14 +267,14 @@ void LLDoNotDisturbNotificationStorage::removeIMNotification(const LLUUID& sessi
     //Remove the notifications
     if(itemsToRemove.size())
     {
-    while(itemsToRemove.size())
-    {
-        it = itemsToRemove.back();
-        notification = it->second;
+        while(itemsToRemove.size())
+        {
+            it = itemsToRemove.back();
+            notification = it->second;
             commChannel->removeItemFromHistory(notification);
-        instance.cancel(notification);
-        itemsToRemove.pop_back();
-    }
+            instance.cancel(notification);
+            itemsToRemove.pop_back();
+        }
         //Trigger saving of notifications to xml once all have been removed
         saveNotifications();
     }
diff --git a/indra/newview/lldonotdisturbnotificationstorage.h b/indra/newview/lldonotdisturbnotificationstorage.h
index fd03b71357..fd7cc7ee82 100644
--- a/indra/newview/lldonotdisturbnotificationstorage.h
+++ b/indra/newview/lldonotdisturbnotificationstorage.h
@@ -42,9 +42,6 @@ public:
     ~LLDoNotDisturbNotificationStorageTimer();
 
 public:
-    void startTimer();
-    void stopTimer();
-    bool isRunning();
     BOOL tick();
 };
 
diff --git a/indra/newview/llfloaterimcontainer.cpp b/indra/newview/llfloaterimcontainer.cpp
index cc23449449..8f290ae7c1 100644
--- a/indra/newview/llfloaterimcontainer.cpp
+++ b/indra/newview/llfloaterimcontainer.cpp
@@ -1299,11 +1299,14 @@ BOOL LLFloaterIMContainer::selectConversationPair(const LLUUID& session_id, bool
     	if (widget && widget->getParentFolder())
     	{
     		widget->getParentFolder()->setSelection(widget, FALSE, FALSE);
-            if(gAgent.isDoNotDisturb())
-            {
-                LLDoNotDisturbNotificationStorage::getInstance()->removeIMNotification(session_id);
-            }
     	}
+
+        //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()->removeIMNotification(session_id);
+        }
     }
 
     /* floater processing */
@@ -1324,11 +1327,6 @@ BOOL LLFloaterIMContainer::selectConversationPair(const LLUUID& session_id, bool
 				// Switch to the conversation floater that is being selected
 				selectFloater(session_floater);
 			}
-
-            if(gAgent.isDoNotDisturb())
-            {
-                LLDoNotDisturbNotificationStorage::getInstance()->removeIMNotification(session_id);
-            }
 		}
 
 		// Set the focus on the selected floater
-- 
cgit v1.2.3


From 68adda3627b0583e01796b229e1c1f920f28ff37 Mon Sep 17 00:00:00 2001
From: Gilbert Gonzales <gilbert@lindenlab.com>
Date: Thu, 17 Jan 2013 14:12:48 -0800
Subject: CHUI-685 removing some commented out code

---
 indra/newview/lldonotdisturbnotificationstorage.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/indra/newview/lldonotdisturbnotificationstorage.cpp b/indra/newview/lldonotdisturbnotificationstorage.cpp
index 5bea7d41f6..824ff67972 100644
--- a/indra/newview/lldonotdisturbnotificationstorage.cpp
+++ b/indra/newview/lldonotdisturbnotificationstorage.cpp
@@ -47,12 +47,12 @@ const std::string toastName = "IMToast";
 
 LLDoNotDisturbNotificationStorageTimer::LLDoNotDisturbNotificationStorageTimer() : LLEventTimer(DND_TIMER)
 {
-    //mEventTimer.start();
+
 }
 
 LLDoNotDisturbNotificationStorageTimer::~LLDoNotDisturbNotificationStorageTimer()
 {
-    //mEventTimer.stop();
+
 }
 
 BOOL LLDoNotDisturbNotificationStorageTimer::tick()
-- 
cgit v1.2.3


From 6c79873d8dcb08c891ecd04f5706e69fe3a75b7d Mon Sep 17 00:00:00 2001
From: Gilbert Gonzales <gilbert@lindenlab.com>
Date: Thu, 17 Jan 2013 15:14:02 -0800
Subject: CHUI-680: Adjusted LLResponderRegistry to be derived from
 LLRegistrySingleton instead of LLResponderRegistry making its over version.

---
 indra/newview/llnotificationstorage.cpp | 93 ++++++++++++---------------------
 1 file changed, 33 insertions(+), 60 deletions(-)

diff --git a/indra/newview/llnotificationstorage.cpp b/indra/newview/llnotificationstorage.cpp
index 4c5b7cc198..b6184f09bf 100644
--- a/indra/newview/llnotificationstorage.cpp
+++ b/indra/newview/llnotificationstorage.cpp
@@ -38,30 +38,43 @@
 #include "llsd.h"
 #include "llsdserialize.h"
 #include "llsingleton.h"
-#include "llviewermessage.h"
+#include "llregistry.h"
+#include "llviewermessage.h" 
 
+typedef boost::function<LLNotificationResponderInterface * (const LLSD& pParams)> responder_constructor_t;
 
-class LLResponderRegistry : public LLSingleton<LLResponderRegistry>
+class LLResponderRegistry : public LLRegistrySingleton<std::string, responder_constructor_t, LLResponderRegistry>
 {
-public:
-	LLResponderRegistry();
-	~LLResponderRegistry();
-	
-	LLNotificationResponderInterface* createResponder(const std::string& pNotificationName, const LLSD& pParams);
-	
-protected:
-	
-private:
-	template<typename RESPONDER_TYPE> static LLNotificationResponderInterface* create(const LLSD& pParams);
-	
-	typedef boost::function<LLNotificationResponderInterface* (const LLSD& params)> responder_constructor_t;
-	
-	void add(const std::string& pNotificationName, const responder_constructor_t& pConstructor);
-	
-	typedef std::map<std::string, responder_constructor_t> build_map_t;
-	build_map_t mBuildMap;
+    public:
+        template<typename RESPONDER_TYPE> static LLNotificationResponderInterface * create(const LLSD& pParams);
+        LLNotificationResponderInterface * createResponder(const std::string& pNotificationName, const LLSD& pParams);
 };
 
+template<typename RESPONDER_TYPE> LLNotificationResponderInterface * LLResponderRegistry::create(const LLSD& pParams)
+{
+    RESPONDER_TYPE* responder = new RESPONDER_TYPE();
+    responder->fromLLSD(pParams);
+    return responder;
+}
+
+
+LLNotificationResponderInterface * LLResponderRegistry::createResponder(const std::string& pNotificationName, const LLSD& pParams)
+{
+    responder_constructor_t * factoryFunc = (LLResponderRegistry::getValue(pNotificationName));
+
+    if(factoryFunc)
+    {
+        return (*factoryFunc)(pParams);
+    }
+    
+    return NULL;
+}
+
+LLResponderRegistry::StaticRegistrar sRegisterObjectGiveItem("ObjectGiveItem", &LLResponderRegistry::create<LLOfferInfo>);
+LLResponderRegistry::StaticRegistrar sRegisterUserGiveItem("UserGiveItem", &LLResponderRegistry::create<LLOfferInfo>);
+LLResponderRegistry::StaticRegistrar sRegisterOfferInfo("offer_info", &LLResponderRegistry::create<LLOfferInfo>);
+
+
 LLNotificationStorage::LLNotificationStorage(std::string pFileName)
 	: mFileName(pFileName)
 {
@@ -116,47 +129,7 @@ bool LLNotificationStorage::readNotifications(LLSD& pNotificationData) const
 	return didFileRead;
 }
 
-LLNotificationResponderInterface* LLNotificationStorage::createResponder(const std::string& pNotificationName, const LLSD& pParams) const
+LLNotificationResponderInterface * LLNotificationStorage::createResponder(const std::string& pNotificationName, const LLSD& pParams) const
 {
 	return LLResponderRegistry::getInstance()->createResponder(pNotificationName, pParams);
 }
-
-LLResponderRegistry::LLResponderRegistry()
-	: LLSingleton<LLResponderRegistry>()
-	, mBuildMap()
-{
-	add("ObjectGiveItem", &create<LLOfferInfo>);
-	add("UserGiveItem", &create<LLOfferInfo>);
-    add("offer_info", &create<LLOfferInfo>);
-}
-
-LLResponderRegistry::~LLResponderRegistry()
-{
-}
-
-LLNotificationResponderInterface* LLResponderRegistry::createResponder(const std::string& pNotificationName, const LLSD& pParams)
-{
-	build_map_t::const_iterator it = mBuildMap.find(pNotificationName);
-	if(mBuildMap.end() == it)
-	{
-		return NULL;
-	}
-	responder_constructor_t ctr = it->second;
-	return ctr(pParams);
-}
-
-template<typename RESPONDER_TYPE> LLNotificationResponderInterface* LLResponderRegistry::create(const LLSD& pParams)
-{
-	RESPONDER_TYPE* responder = new RESPONDER_TYPE();
-	responder->fromLLSD(pParams);
-	return responder;
-}
-	
-void LLResponderRegistry::add(const std::string& pNotificationName, const responder_constructor_t& pConstructor)
-{
-	if (mBuildMap.find(pNotificationName) != mBuildMap.end())
-	{
-		LL_ERRS("LLResponderRegistry") << "Responder is already registered : " << pNotificationName << LL_ENDL;
-	}
-	mBuildMap.insert(std::make_pair<std::string, responder_constructor_t>(pNotificationName, pConstructor));
-}
-- 
cgit v1.2.3


From d0235ad1789d05524065307f4514a76d55f4e847 Mon Sep 17 00:00:00 2001
From: Gilbert Gonzales <gilbert@lindenlab.com>
Date: Thu, 17 Jan 2013 16:06:08 -0800
Subject: CHUI-604: Problem: DND response was inside of the responder for the
 inventory offer. Resolution: DND response is now sent upon receiving an offer
 notification from an agent.

---
 indra/newview/llviewermessage.cpp | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index db81e057de..9878f9bc81 100755
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -1618,12 +1618,6 @@ bool LLOfferInfo::inventory_offer_callback(const LLSD& notification, const LLSD&
 			{
 				opener = discard_agent_offer;
 			}
-			
-			
-			if (gAgent.isDoNotDisturb() && (!mFromGroup && !mFromObject))
-			{
-				send_do_not_disturb_message(gMessageSystem, mFromID);
-			}
 
 			if (modified_form != NULL)
 			{
@@ -1991,6 +1985,11 @@ void inventory_offer_handler(LLOfferInfo* info)
 		// In viewer 2 we're now auto receiving inventory offers and messaging as such (not sending reject messages).
 		info->send_auto_receive_response();
 
+        if (gAgent.isDoNotDisturb()) 
+        {
+            send_do_not_disturb_message(gMessageSystem, info->mFromID);
+        }
+
 		// Inform user that there is a script floater via toast system
 		{
 			payload["give_inventory_notification"] = TRUE;
-- 
cgit v1.2.3