diff options
Diffstat (limited to 'indra/llcommon')
| -rw-r--r-- | indra/llcommon/llavatarname.cpp | 75 | ||||
| -rw-r--r-- | indra/llcommon/llavatarname.h | 13 | 
2 files changed, 66 insertions, 22 deletions
| diff --git a/indra/llcommon/llavatarname.cpp b/indra/llcommon/llavatarname.cpp index b49e6a7aac..95ecce509b 100644 --- a/indra/llcommon/llavatarname.cpp +++ b/indra/llcommon/llavatarname.cpp @@ -45,6 +45,12 @@ static const std::string DISPLAY_NAME_NEXT_UPDATE("display_name_next_update");  bool LLAvatarName::sUseDisplayNames = true; +// Minimum time-to-live (in seconds) for a name entry. +// Avatar name should always guarantee to expire reasonably soon by default +// so if the failure to get a valid expiration time was due to something temporary  +// we will eventually request and get the right data. +const F64 MIN_ENTRY_LIFETIME = 60.0; +  LLAvatarName::LLAvatarName()  :	mUsername(),  	mDisplayName(), @@ -107,40 +113,67 @@ void LLAvatarName::fromLLSD(const LLSD& sd)  	}  } -void LLAvatarName::fromString(const std::string& full_name, F64 expires) +// Transform a string (typically provided by the legacy service) into a decent +// avatar name instance. +void LLAvatarName::fromString(const std::string& full_name)  {  	mDisplayName = full_name;  	std::string::size_type index = full_name.find(' ');  	if (index != std::string::npos)  	{ +		// The name is in 2 parts (first last)  		mLegacyFirstName = full_name.substr(0, index);  		mLegacyLastName = full_name.substr(index+1); -		mUsername = mLegacyFirstName + " " + mLegacyLastName; +		if (mLegacyLastName != "Resident") +		{ +			mUsername = mLegacyFirstName + "." + mLegacyLastName; +			mDisplayName = full_name; +			LLStringUtil::toLower(mUsername); +		} +		else +		{ +			// Very old names do have a dummy "Resident" last name  +			// that we choose to hide from users. +			mUsername = mLegacyFirstName; +			mDisplayName = mLegacyFirstName; +		}  	}  	else  	{  		mLegacyFirstName = full_name;  		mLegacyLastName = "";  		mUsername = full_name; +		mDisplayName = full_name;  	}  	mIsDisplayNameDefault = true;  	mIsTemporaryName = true; +	setExpires(MIN_ENTRY_LIFETIME); +} + +void LLAvatarName::setExpires(F64 expires) +{  	mExpires = LLFrameTimer::getTotalSeconds() + expires;  }  std::string LLAvatarName::getCompleteName() const  {  	std::string name; -	if (mUsername.empty() || mIsDisplayNameDefault) -	// If the display name feature is off -	// OR this particular display name is defaulted (i.e. based on user name), -	// then display only the easier to read instance of the person's name. +	if (sUseDisplayNames)  	{ -		name = mDisplayName; +		if (mUsername.empty() || mIsDisplayNameDefault) +		{ +			// If this particular display name is defaulted (i.e. based on user name), +			// then display only the easier to read instance of the person's name. +			name = mDisplayName; +		} +		else +		{ +			name = mDisplayName + " (" + mUsername + ")"; +		}  	}  	else  	{ -		name = mDisplayName + " (" + mUsername + ")"; +		name = getUserName();  	}  	return name;  } @@ -159,23 +192,29 @@ std::string LLAvatarName::getDisplayName() const  std::string LLAvatarName::getUserName() const  { -	// If we cannot create a user name from the legacy strings, use the display name -	if (mLegacyFirstName.empty() && mLegacyLastName.empty()) +	std::string name; +	if (mLegacyLastName.empty() || (mLegacyLastName == "Resident"))  	{ -		return mDisplayName; +		if (mLegacyFirstName.empty()) +		{ +			// If we cannot create a user name from the legacy strings, use the display name +			name = mDisplayName; +		} +		else +		{ +			// The last name might be empty if it defaulted to "Resident" +			name = mLegacyFirstName; +		} +	} +	else +	{ +		name = mLegacyFirstName + " " + mLegacyLastName;  	} - -	std::string name; -	name.reserve( mLegacyFirstName.size() + 1 + mLegacyLastName.size() ); -	name = mLegacyFirstName; -	name += " "; -	name += mLegacyLastName;  	return name;  }  void LLAvatarName::dump() const  { -	llinfos << "Merov debug : display = " << mDisplayName << ", user = " << mUsername << ", complete = " << getCompleteName() << ", legacy = " << getUserName() << " first = " << mLegacyFirstName << " last = " << mLegacyLastName << llendl;  	LL_DEBUGS("AvNameCache") << "LLAvatarName: "  	                         << "user '" << mUsername << "' "  							 << "display '" << mDisplayName << "' " diff --git a/indra/llcommon/llavatarname.h b/indra/llcommon/llavatarname.h index cf9eb27b03..2f8c534974 100644 --- a/indra/llcommon/llavatarname.h +++ b/indra/llcommon/llavatarname.h @@ -39,20 +39,25 @@ public:  	bool operator<(const LLAvatarName& rhs) const; +	// Conversion to and from LLSD (cache file or server response)  	LLSD asLLSD() const; -  	void fromLLSD(const LLSD& sd);  	// Used only in legacy mode when the display name capability is not provided server side -	void fromString(const std::string& full_name, F64 expires = 0.0f); +	// or to otherwise create a temporary valid item. +	void fromString(const std::string& full_name); +	// Set the name object to become invalid in "expires" seconds from now +	void setExpires(F64 expires); + +	// Set and get the display name flag set by the user in preferences.  	static void setUseDisplayNames(bool use);  	static bool useDisplayNames(); -	// Name is valid if not temporary and not yet expired +	// A name object is valid if not temporary and not yet expired (default is expiration not checked)  	bool isValidName(F64 max_unrefreshed = 0.0f) const { return !mIsTemporaryName && (mExpires >= max_unrefreshed); } -	//  +	// Return true if the name is made up from legacy or temporary data  	bool isDisplayNameDefault() const { return mIsDisplayNameDefault; }  	// For normal names, returns "James Linden (james.linden)" | 
