From a6f1690128b510977cfe86071f80f81967b9d0c7 Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Fri, 7 Dec 2012 18:58:52 -0800
Subject: CHUI-580, CHUI-406 : Fixed : Finished avatar name caching, also fixed
 the display of (waiting) when names don't come (mostly in legacy mode).

---
 indra/llmessage/llavatarnamecache.cpp | 39 ++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 12 deletions(-)

(limited to 'indra/llmessage')

diff --git a/indra/llmessage/llavatarnamecache.cpp b/indra/llmessage/llavatarnamecache.cpp
index 15c4f2a207..9d6aa15ed1 100644
--- a/indra/llmessage/llavatarnamecache.cpp
+++ b/indra/llmessage/llavatarnamecache.cpp
@@ -100,11 +100,14 @@ namespace LLAvatarNameCache
 
 	void requestNamesViaCapability();
 
-	// Legacy name system callback
+	// Legacy name system callbacks
 	void legacyNameCallback(const LLUUID& agent_id,
 							const std::string& full_name,
 							bool is_group);
-
+	void legacyNameFetch(const LLUUID& agent_id,
+						 const std::string& full_name,
+						 bool is_group);
+	
 	void requestNamesViaLegacy();
 
 	// Do a single callback to a given slot
@@ -262,8 +265,7 @@ void LLAvatarNameCache::handleAgentError(const LLUUID& agent_id)
         LL_WARNS("AvNameCache") << "LLAvatarNameCache get legacy for agent "
 								<< agent_id << LL_ENDL;
         gCacheName->get(agent_id, false,  // legacy compatibility
-                        boost::bind(&LLAvatarNameCache::legacyNameCallback,
-                                    _1, _2, _3));
+                        boost::bind(&LLAvatarNameCache::legacyNameFetch, _1, _2, _3));
     }
 	else
     {
@@ -367,19 +369,32 @@ void LLAvatarNameCache::legacyNameCallback(const LLUUID& agent_id,
 										   const std::string& full_name,
 										   bool is_group)
 {
-	LL_DEBUGS("AvNameCache") << "LLAvatarNameCache::legacyNameCallback "
-							 << "agent " << agent_id << " "
+	// Put the received data in the cache
+	legacyNameFetch(agent_id, full_name, is_group);
+	
+	// Retrieve the name and set it to never (or almost never...) expire: when we are using the legacy
+	// protocol, we do not get an expiration date for each name and there's no reason to ask the 
+	// data again and again so we set the expiration time to the largest value admissible.
+	std::map<LLUUID,LLAvatarName>::iterator av_record = sCache.find(agent_id);
+	LLAvatarName& av_name = av_record->second;
+	av_name.setExpires(MAX_UNREFRESHED_TIME);
+}
+
+void LLAvatarNameCache::legacyNameFetch(const LLUUID& agent_id,
+										const std::string& full_name,
+										bool is_group)
+{
+	LL_DEBUGS("AvNameCache") << "LLAvatarNameCache::legacyNameFetch "
+	                         << "agent " << agent_id << " "
 							 << "full name '" << full_name << "'"
-							 << ( is_group ? " [group]" : "" )
-							 << LL_ENDL;
+	                         << ( is_group ? " [group]" : "" )
+	                         << LL_ENDL;
 	
 	// Construct an av_name record from this name.
 	LLAvatarName av_name;
 	av_name.fromString(full_name);
-	av_name.dump();
-
-	// Add to cache, because if we don't we'll keep rerequesting the
-	// same record forever.
+	
+	// Add to cache: we're still using the new cache even if we're using the old (legacy) protocol.
 	processName(agent_id, av_name);
 }
 
-- 
cgit v1.2.3