From 125f3f071a30f4c47feb664b21f3e380ee4e7e49 Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Mon, 18 Nov 2013 16:03:22 -0800
Subject: [PATCH] MAINT-3319 : WIP : Introduce a consolidate folder method used
 for Merchant Outbox

---
 indra/newview/llfloateroutbox.cpp  |  5 +++++
 indra/newview/llinventorymodel.cpp | 23 +++++++++++++++++++----
 indra/newview/llinventorymodel.h   |  5 +++++
 3 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/indra/newview/llfloateroutbox.cpp b/indra/newview/llfloateroutbox.cpp
index fa628f2a085..90da9ad2c09 100755
--- a/indra/newview/llfloateroutbox.cpp
+++ b/indra/newview/llfloateroutbox.cpp
@@ -238,6 +238,11 @@ void LLFloaterOutbox::setupOutbox()
 		llerrs << "Inventory problem: failure to create the outbox for a merchant!" << llendl;
 		return;
 	}
+    
+    // Consolidate Merchant Outbox
+    // We shouldn't have to do that but with a client/server system relying on a "well known folder" convention, things get messy and conventions get broken down eventually
+    gInventory.consolidateForType(outbox_id, LLFolderType::FT_OUTBOX);
+    
     if (outbox_id == mOutboxId)
     {
         llwarns << "Inventory warning: Merchant outbox already set" << llendl;
diff --git a/indra/newview/llinventorymodel.cpp b/indra/newview/llinventorymodel.cpp
index 935fe2b4d0e..18dbce3321f 100755
--- a/indra/newview/llinventorymodel.cpp
+++ b/indra/newview/llinventorymodel.cpp
@@ -369,15 +369,30 @@ void LLInventoryModel::unlockDirectDescendentArrays(const LLUUID& cat_id)
 	mItemLock[cat_id] = false;
 }
 
+void LLInventoryModel::consolidateForType(const LLUUID& id, LLFolderType::EType type)
+{
+    bool trace = (type == LLFolderType::FT_OUTBOX);
+    if (trace)
+    {
+        for (cat_map_t::iterator cit = mCategoryMap.begin(); cit != mCategoryMap.end(); ++cit)
+        {
+            LLViewerInventoryCategory* cat = cit->second;
+            if (cat->getPreferredType() == type)
+            {
+                llinfos << "Merov : List outbox from mCategoryMap, name = " << cat->getName() << ", type = " << cat->getPreferredType() << ", id = " << cat->getUUID().asString() << llendl;
+            }
+        }
+    }
+}
+
 // findCategoryUUIDForType() returns the uuid of the category that
 // specifies 'type' as what it defaults to containing. The category is
 // not necessarily only for that type. *NOTE: This will create a new
 // inventory category on the fly if one does not exist.
-const LLUUID LLInventoryModel::findCategoryUUIDForType(LLFolderType::EType preferred_type, bool create_folder/*, 
+const LLUUID LLInventoryModel::findCategoryUUIDForType(LLFolderType::EType preferred_type, bool create_folder/*,
 					  bool find_in_library*/)
 {
 	LLUUID rv = LLUUID::null;
-	
 	const LLUUID &root_id = /*(find_in_library) ? gInventory.getLibraryRootFolderID() :*/ gInventory.getRootFolderID();
 	if(LLFolderType::FT_ROOT_INVENTORY == preferred_type)
 	{
@@ -392,9 +407,9 @@ const LLUUID LLInventoryModel::findCategoryUUIDForType(LLFolderType::EType prefe
 			S32 count = cats->count();
 			for(S32 i = 0; i < count; ++i)
 			{
-				if(cats->get(i)->getPreferredType() == preferred_type)
+				if (cats->get(i)->getPreferredType() == preferred_type)
 				{
-					rv = cats->get(i)->getUUID();
+                    rv = cats->get(i)->getUUID();
 					break;
 				}
 			}
diff --git a/indra/newview/llinventorymodel.h b/indra/newview/llinventorymodel.h
index 8aac879a937..544ca5e5dcc 100755
--- a/indra/newview/llinventorymodel.h
+++ b/indra/newview/llinventorymodel.h
@@ -263,6 +263,11 @@ class LLInventoryModel
 	// Get the inventoryID or item that this item points to, else just return object_id
 	const LLUUID& getLinkedItemID(const LLUUID& object_id) const;
 	LLViewerInventoryItem* getLinkedItem(const LLUUID& object_id) const;
+    
+    // Copy content of all folders of type "type" into folder "id" and delete/purge the empty folders
+    // Note : This method has been designed for FT_OUTBOX (aka Merchant Outbox) but can be used for other categories
+    void consolidateForType(const LLUUID& id, LLFolderType::EType type);
+    
 private:
 	mutable LLPointer<LLViewerInventoryItem> mLastItem; // cache recent lookups	
 
-- 
GitLab