From 77753a31aba6123696761aeeb2c535768fd1ea12 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Tue, 4 Apr 2023 02:08:23 +0300
Subject: SL-19188 Improve legacy gallery thumbnail support

---
 indra/newview/llfloaterchangeitemthumbnail.cpp | 32 +++++++++++++++++++-------
 indra/newview/llfloaterchangeitemthumbnail.h   |  6 +++--
 2 files changed, 28 insertions(+), 10 deletions(-)

(limited to 'indra')

diff --git a/indra/newview/llfloaterchangeitemthumbnail.cpp b/indra/newview/llfloaterchangeitemthumbnail.cpp
index 8f6d984aa9..099ceea821 100644
--- a/indra/newview/llfloaterchangeitemthumbnail.cpp
+++ b/indra/newview/llfloaterchangeitemthumbnail.cpp
@@ -335,7 +335,7 @@ void LLFloaterChangeItemThumbnail::refreshFromObject(LLInventoryObject* obj)
     LLViewerInventoryItem* item = dynamic_cast<LLViewerInventoryItem*>(obj);
     if (item)
     {
-        // This floater probably shouldn't be be possible to open
+        // This floater probably shouldn't be possible to open
         // for imcomplete items
         llassert(item->isFinished());
 
@@ -369,13 +369,14 @@ void LLFloaterChangeItemThumbnail::refreshFromObject(LLInventoryObject* obj)
                     }
                     if (item)
                     {
-                        LL_INFOS() << "Setting image from outfit as a thumbnail" << LL_ENDL;
                         thumbnail_id = item->getAssetUUID();
-
-                        if (validateAsset(thumbnail_id))
+                        if (thumbnail_id.notNull())
                         {
                             // per SL-19188, set this image as a thumbnail
-                            setThumbnailId(thumbnail_id);
+                            LL_INFOS() << "Setting image " << thumbnail_id
+                                       << " from outfit as a thumbnail for inventory object " << obj->getUUID()
+                                       << LL_ENDL;
+                            assignAndValidateAsset(thumbnail_id, true);
                         }
                     }
                 }
@@ -540,11 +541,20 @@ void LLFloaterChangeItemThumbnail::onRemovalConfirmation(const LLSD& notificatio
     }
 }
 
-void LLFloaterChangeItemThumbnail::assignAndValidateAsset(const LLUUID &asset_id)
+void LLFloaterChangeItemThumbnail::assignAndValidateAsset(const LLUUID &asset_id, bool silent)
 {
     LLPointer<LLViewerFetchedTexture> texturep = LLViewerTextureManager::getFetchedTexture(asset_id);
     if (texturep->getFullWidth() == 0 && !texturep->isFullyLoaded() && !texturep->isMissingAsset())
     {
+        if (silent)
+        {
+            mExpectingAssetId = LLUUID::null;
+        }
+        else
+        {
+            // don't warn user multiple times if some textures took their time
+            mExpectingAssetId = asset_id;
+        }
         texturep->setLoadedCallback(onImageLoaded,
             MAX_DISCARD_LEVEL, // don't actually need max one, 3 or 4 should be enough
             FALSE,
@@ -559,7 +569,7 @@ void LLFloaterChangeItemThumbnail::assignAndValidateAsset(const LLUUID &asset_id
         {
             setThumbnailId(asset_id);
         }
-        else
+        else if (!silent)
         {
             LLNotificationsUtil::add("ThumbnailDimentionsLimit");
         }
@@ -567,6 +577,11 @@ void LLFloaterChangeItemThumbnail::assignAndValidateAsset(const LLUUID &asset_id
 }
 bool LLFloaterChangeItemThumbnail::validateAsset(const LLUUID &asset_id)
 {
+    if (asset_id.isNull())
+    {
+        return false;
+    }
+
     LLPointer<LLViewerFetchedTexture> texturep = LLViewerTextureManager::findFetchedTexture(asset_id, TEX_LIST_STANDARD);
 
     if (!texturep)
@@ -624,9 +639,10 @@ void LLFloaterChangeItemThumbnail::onImageLoaded(
             {
                 self->setThumbnailId(asset_id);
             }
-            else
+            else if (self->mExpectingAssetId == asset_id)
             {
                 LLNotificationsUtil::add("ThumbnailDimentionsLimit");
+                self->mExpectingAssetId = LLUUID::null;
             }
         }
     }
diff --git a/indra/newview/llfloaterchangeitemthumbnail.h b/indra/newview/llfloaterchangeitemthumbnail.h
index 18cf2f7a85..33bf2ecab5 100644
--- a/indra/newview/llfloaterchangeitemthumbnail.h
+++ b/indra/newview/llfloaterchangeitemthumbnail.h
@@ -66,6 +66,8 @@ public:
         S32 serial_num,
         void* user_data) override;
 
+    static bool validateAsset(const LLUUID &asset_id);
+
 private:
 
     LLInventoryObject* getInventoryObject();
@@ -80,8 +82,7 @@ private:
     static void onRemove(void*);
     static void onRemovalConfirmation(const LLSD& notification, const LLSD& response, LLHandle<LLFloater> handle);
 
-    void assignAndValidateAsset(const LLUUID &asset_id);
-    static bool validateAsset(const LLUUID &asset_id);
+    void assignAndValidateAsset(const LLUUID &asset_id, bool silent = false);
     static void onImageLoaded(BOOL success,
         LLViewerFetchedTexture *src_vi,
         LLImageRaw* src,
@@ -113,6 +114,7 @@ private:
     EToolTipState mTooltipState;
     LLUUID mItemId;
     LLUUID mTaskId;
+    LLUUID mExpectingAssetId;
 
     LLIconCtrl *mItemTypeIcon;
     LLUICtrl *mItemNameText;
-- 
cgit v1.2.3