From 316bf51482c17b1a03567d37488067af9c412493 Mon Sep 17 00:00:00 2001
From: Ansariel <none@none>
Date: Tue, 21 Jan 2014 15:11:10 +0100
Subject: [PATCH] MAINT-3187: Name list controls do not properly resolve avatar
 names

---
 doc/contributions.txt            |  1 +
 indra/newview/llnamelistctrl.cpp | 33 ++++++++++++++++++++++++--------
 indra/newview/llnamelistctrl.h   | 13 +++++++++----
 3 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/doc/contributions.txt b/doc/contributions.txt
index 2f9d0c2c86e..351b84ecd19 100755
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -180,6 +180,7 @@ Ansariel Hiller
 	MAINT-2368
 	STORM-1931
 	MAINT-2773
+	MAINT-3187
 Aralara Rajal
 Arare Chantilly
 	CHUIBUG-191
diff --git a/indra/newview/llnamelistctrl.cpp b/indra/newview/llnamelistctrl.cpp
index 7ddd04fed0a..3b5a69fd3ac 100755
--- a/indra/newview/llnamelistctrl.cpp
+++ b/indra/newview/llnamelistctrl.cpp
@@ -64,8 +64,7 @@ LLNameListCtrl::LLNameListCtrl(const LLNameListCtrl::Params& p)
 	mNameColumnIndex(p.name_column.column_index),
 	mNameColumn(p.name_column.column_name),
 	mAllowCallingCardDrop(p.allow_calling_card_drop),
-	mShortNames(p.short_names),
-	mAvatarNameCacheConnection()
+	mShortNames(p.short_names)
 {}
 
 // public
@@ -328,13 +327,16 @@ LLScrollListItem* LLNameListCtrl::addNameItemRow(
 			else
 			{
 				// ...schedule a callback
-				// This is not correct and will likely lead to partially populated lists in cases where avatar names are not cached.
-				// *TODO : Change this to have 2 callbacks : one callback per list item and one for the whole list.
-				if (mAvatarNameCacheConnection.connected())
+				avatar_name_cache_connection_map_t::iterator it = mAvatarNameCacheConnections.find(id);
+				if (it != mAvatarNameCacheConnections.end())
 				{
-					mAvatarNameCacheConnection.disconnect();
+					if (it->second.connected())
+					{
+						it->second.disconnect();
+					}
+					mAvatarNameCacheConnections.erase(it);
 				}
-				mAvatarNameCacheConnection = LLAvatarNameCache::get(id,boost::bind(&LLNameListCtrl::onAvatarNameCache,this, _1, _2, item->getHandle()));
+				mAvatarNameCacheConnections[id] = LLAvatarNameCache::get(id,boost::bind(&LLNameListCtrl::onAvatarNameCache,this, _1, _2, suffix, item->getHandle()));
 			}
 			break;
 		}
@@ -391,9 +393,18 @@ void LLNameListCtrl::removeNameItem(const LLUUID& agent_id)
 
 void LLNameListCtrl::onAvatarNameCache(const LLUUID& agent_id,
 									   const LLAvatarName& av_name,
+									   std::string suffix,
 									   LLHandle<LLNameListItem> item)
 {
-	mAvatarNameCacheConnection.disconnect();
+	avatar_name_cache_connection_map_t::iterator it = mAvatarNameCacheConnections.find(agent_id);
+	if (it != mAvatarNameCacheConnections.end())
+	{
+		if (it->second.connected())
+		{
+			it->second.disconnect();
+		}
+		mAvatarNameCacheConnections.erase(it);
+	}
 
 	std::string name;
 	if (mShortNames)
@@ -401,6 +412,12 @@ void LLNameListCtrl::onAvatarNameCache(const LLUUID& agent_id,
 	else
 		name = av_name.getCompleteName();
 
+	// Append optional suffix.
+	if (!suffix.empty())
+	{
+		name.append(suffix);
+	}
+
 	LLNameListItem* list_item = item.get();
 	if (list_item && list_item->getUUID() == agent_id)
 	{
diff --git a/indra/newview/llnamelistctrl.h b/indra/newview/llnamelistctrl.h
index 92e82b672d3..4ed260d8475 100755
--- a/indra/newview/llnamelistctrl.h
+++ b/indra/newview/llnamelistctrl.h
@@ -114,10 +114,14 @@ class LLNameListCtrl
 	LLNameListCtrl(const Params&);
 	virtual ~LLNameListCtrl()
 	{
-		if (mAvatarNameCacheConnection.connected())
+		for (avatar_name_cache_connection_map_t::iterator it = mAvatarNameCacheConnections.begin(); it != mAvatarNameCacheConnections.end(); ++it)
 		{
-			mAvatarNameCacheConnection.disconnect();
+			if (it->second.connected())
+			{
+				it->second.disconnect();
+			}
 		}
+		mAvatarNameCacheConnections.clear();
 	}
 	friend class LLUICtrlFactory;
 public:
@@ -155,14 +159,15 @@ class LLNameListCtrl
 	/*virtual*/ void	mouseOverHighlightNthItem( S32 index );
 private:
 	void showInspector(const LLUUID& avatar_id, bool is_group);
-	void onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name, LLHandle<LLNameListItem> item);
+	void onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name, std::string suffix, LLHandle<LLNameListItem> item);
 
 private:
 	S32    			mNameColumnIndex;
 	std::string		mNameColumn;
 	BOOL			mAllowCallingCardDrop;
 	bool			mShortNames;  // display name only, no SLID
-	boost::signals2::connection mAvatarNameCacheConnection;
+	typedef std::map<LLUUID, boost::signals2::connection> avatar_name_cache_connection_map_t;
+	avatar_name_cache_connection_map_t mAvatarNameCacheConnections;
 };
 
 
-- 
GitLab