Commits

Paul ProductEngine committed 7f71408

MAINT-830 FIXED ([PUBLIC]"Items successfully shared" appears even when share fails)

- Added check whether sharing inventory category or inventory item was successful

  • Participants
  • Parent commits 4967fc3

Comments (0)

Files changed (3)

File indra/newview/llavataractions.cpp

 		}
 
 		S32 count = LLShareInfo::instance().mAvatarNames.size();
-		bool shared = false;
+		bool shared = count && !inventory_selected_uuids.empty();
 
 		// iterate through avatars
 		for(S32 i = 0; i < count; ++i)
 				LLViewerInventoryCategory* inv_cat = gInventory.getCategory(*it);
 				if (inv_cat)
 				{
-					LLGiveInventory::doGiveInventoryCategory(avatar_uuid, inv_cat, session_id);
-					shared = true;
+					if (!LLGiveInventory::doGiveInventoryCategory(avatar_uuid, inv_cat, session_id, "ItemsShared"))
+					{
+						shared = false;
+					}
 					break;
 				}
 				LLViewerInventoryItem* inv_item = gInventory.getItem(*it);
 				}
 				else
 				{
-				LLGiveInventory::doGiveInventoryItem(avatar_uuid, inv_item, session_id);
-					shared = true;
+					if (!LLGiveInventory::doGiveInventoryItem(avatar_uuid, inv_item, session_id))
+					{
+						shared = false;
+					}
 				}
 			}
 			if (noncopy_items.beginArray() != noncopy_items.endArray())
 				LLSD payload;
 				payload["agent_id"] = avatar_uuid;
 				payload["items"] = noncopy_items;
+				payload["success_notification"] = "ItemsShared";
 				LLNotificationsUtil::add("CannotCopyWarning", substitutions, payload,
 					&LLGiveInventory::handleCopyProtectedItem);
+				shared = false;
 				break;
 			}
 		}

File indra/newview/llgiveinventory.cpp

 	return res;
 }
 
-void LLGiveInventory::doGiveInventoryCategory(const LLUUID& to_agent,
+bool LLGiveInventory::doGiveInventoryCategory(const LLUUID& to_agent,
 											  const LLInventoryCategory* cat,
-											  const LLUUID& im_session_id)
+											  const LLUUID& im_session_id,
+											  const std::string& notification_name)
 
 {
-	if (!cat) return;
+	if (!cat)
+	{
+		return false;
+	}
 	llinfos << "LLGiveInventory::giveInventoryCategory() - "
 		<< cat->getUUID() << llendl;
 
-	if (!isAgentAvatarValid()) return;
+	if (!isAgentAvatarValid())
+	{
+		return false;
+	}
 
+	bool give_successful = true;
 	// Test out how many items are being given.
 	LLViewerInventoryCategory::cat_array_t cats;
 	LLViewerInventoryItem::item_array_t items;
 	if (!complete)
 	{
 		LLNotificationsUtil::add("IncompleteInventory");
-		return;
+		give_successful = false;
 	}
 	count = items.count() + cats.count();
 	if (count > MAX_ITEMS)
 	{
 		LLNotificationsUtil::add("TooManyItems");
-		return;
+		give_successful = false;
 	}
 	else if (count == 0)
 	{
 		LLNotificationsUtil::add("NoItems");
-		return;
+		give_successful = false;
 	}
-	else
+	else if (give_successful)
 	{
 		if (0 == giveable.countNoCopy())
 		{
-			LLGiveInventory::commitGiveInventoryCategory(to_agent, cat, im_session_id);
+			give_successful = LLGiveInventory::commitGiveInventoryCategory(to_agent, cat, im_session_id);
 		}
 		else
 		{
 			LLSD payload;
 			payload["agent_id"] = to_agent;
 			payload["folder_id"] = cat->getUUID();
+			if (!notification_name.empty())
+			{
+				payload["success_notification"] = notification_name;
+			}
 			LLNotificationsUtil::add("CannotCopyCountItems", args, payload, &LLGiveInventory::handleCopyProtectedCategory);
+			give_successful = false;
 		}
 	}
+
+	return give_successful;
 }
 
 //////////////////////////////////////////////////////////////////////////
 	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 	LLSD itmes = notification["payload"]["items"];
 	LLInventoryItem* item = NULL;
+	bool give_successful = true;
 	switch(option)
 	{
 	case 0:  // "Yes"
 			else
 			{
 				LLNotificationsUtil::add("CannotGiveItem");
+				give_successful = false;
 			}
 		}
+		if (give_successful && notification["payload"]["success_notification"].isDefined())
+		{
+			LLNotificationsUtil::add(notification["payload"]["success_notification"].asString());
+		}
 		break;
 
 	default: // no, cancel, whatever, who cares, not yes.
 		LLNotificationsUtil::add("TransactionCancelled");
+		give_successful = false;
 		break;
 	}
-	return false;
+	return give_successful;
 }
 
 // static
 {
 	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 	LLInventoryCategory* cat = NULL;
+	bool give_successful = true;
 	switch(option)
 	{
 	case 0:  // "Yes"
 		cat = gInventory.getCategory(notification["payload"]["folder_id"].asUUID());
 		if (cat)
 		{
-			LLGiveInventory::commitGiveInventoryCategory(notification["payload"]["agent_id"].asUUID(),
+			give_successful = LLGiveInventory::commitGiveInventoryCategory(notification["payload"]["agent_id"].asUUID(),
 				cat);
 			LLViewerInventoryCategory::cat_array_t cats;
 			LLViewerInventoryItem::item_array_t items;
 				gInventory.deleteObject(items.get(i)->getUUID());
 			}
 			gInventory.notifyObservers();
+
+			if (give_successful && notification["payload"]["success_notification"].isDefined())
+			{
+				LLNotificationsUtil::add(notification["payload"]["success_notification"].asString());
+			}
 		}
 		else
 		{
 			LLNotificationsUtil::add("CannotGiveCategory");
+			give_successful = false;
 		}
 		break;
 
 	default: // no, cancel, whatever, who cares, not yes.
 		LLNotificationsUtil::add("TransactionCancelled");
+		give_successful = false;
 		break;
 	}
-	return false;
+	return give_successful;
 }
 
 // static
-void LLGiveInventory::commitGiveInventoryCategory(const LLUUID& to_agent,
+bool LLGiveInventory::commitGiveInventoryCategory(const LLUUID& to_agent,
 													const LLInventoryCategory* cat,
 													const LLUUID& im_session_id)
 
 {
-	if (!cat) return;
+	if (!cat)
+	{
+		return false;
+	}
 	llinfos << "LLGiveInventory::commitGiveInventoryCategory() - "
 		<< cat->getUUID() << llendl;
 
 		LLInventoryModel::EXCLUDE_TRASH,
 		giveable);
 
+	bool give_successful = true;
 	// MAX ITEMS is based on (sizeof(uuid)+2) * count must be <
 	// MTUBYTES or 18 * count < 1200 => count < 1200/18 =>
 	// 66. I've cut it down a bit from there to give some pad.
 	if (count > MAX_ITEMS)
 	{
 		LLNotificationsUtil::add("TooManyItems");
-		return;
+		give_successful = false;
 	}
 	else if (count == 0)
 	{
 		LLNotificationsUtil::add("NoItems");
-		return;
+		give_successful = false;
 	}
 	else
 	{
 
 		logInventoryOffer(to_agent, im_session_id);
 	}
+
+	return give_successful;
 }
 
 // EOF

File indra/newview/llgiveinventory.h

 	/**
 	 * Gives passed inventory category to specified avatar in specified session.
 	 */
-	static void doGiveInventoryCategory(const LLUUID& to_agent,
+	static bool doGiveInventoryCategory(const LLUUID& to_agent,
 									const LLInventoryCategory* item,
-									const LLUUID &session_id = LLUUID::null);
+									const LLUUID &session_id = LLUUID::null,
+									const std::string& notification = std::string());
 
 	// give inventory item functionality
 	static bool handleCopyProtectedItem(const LLSD& notification, const LLSD& response);
 
 	// give inventory category functionality
 	static bool handleCopyProtectedCategory(const LLSD& notification, const LLSD& response);
-	static void commitGiveInventoryCategory(const LLUUID& to_agent,
+	static bool commitGiveInventoryCategory(const LLUUID& to_agent,
 									const LLInventoryCategory* cat,
 									const LLUUID &im_session_id = LLUUID::null);