From c7a6a2e08f34b2cd21816a905c21e8017646001c Mon Sep 17 00:00:00 2001
From: James Cook <james@lindenlab.com>
Date: Thu, 27 May 2010 14:56:29 -0700
Subject: [PATCH] DEV-50013 Friendlier info if you can't change name due to
 time lockout

Reviewed with Leyla
---
 indra/llcommon/llavatarname.cpp               |  7 ++-
 indra/llcommon/llavatarname.h                 |  5 ++
 indra/llcommon/llstring.cpp                   | 11 +++--
 indra/newview/llpanelme.cpp                   | 48 ++++++++++++-------
 .../skins/default/xui/en/notifications.xml    | 25 ++++++++--
 5 files changed, 69 insertions(+), 27 deletions(-)

diff --git a/indra/llcommon/llavatarname.cpp b/indra/llcommon/llavatarname.cpp
index 6e0582f865f..14dc41591b7 100644
--- a/indra/llcommon/llavatarname.cpp
+++ b/indra/llcommon/llavatarname.cpp
@@ -46,6 +46,7 @@ static const std::string LEGACY_FIRST_NAME("legacy_first_name");
 static const std::string LEGACY_LAST_NAME("legacy_last_name");
 static const std::string IS_DISPLAY_NAME_DEFAULT("is_display_name_default");
 static const std::string DISPLAY_NAME_EXPIRES("display_name_expires");
+static const std::string DISPLAY_NAME_NEXT_UPDATE("display_name_next_update");
 
 LLAvatarName::LLAvatarName()
 :	mUsername(),
@@ -54,7 +55,8 @@ LLAvatarName::LLAvatarName()
 	mLegacyLastName(),
 	mIsDisplayNameDefault(false),
 	mIsDummy(false),
-	mExpires(F64_MAX)
+	mExpires(F64_MAX),
+	mNextUpdate(0.0)
 { }
 
 bool LLAvatarName::operator<(const LLAvatarName& rhs) const
@@ -74,6 +76,7 @@ LLSD LLAvatarName::asLLSD() const
 	sd[LEGACY_LAST_NAME] = mLegacyLastName;
 	sd[IS_DISPLAY_NAME_DEFAULT] = mIsDisplayNameDefault;
 	sd[DISPLAY_NAME_EXPIRES] = LLDate(mExpires);
+	sd[DISPLAY_NAME_NEXT_UPDATE] = LLDate(mNextUpdate);
 	return sd;
 }
 
@@ -86,6 +89,8 @@ void LLAvatarName::fromLLSD(const LLSD& sd)
 	mIsDisplayNameDefault = sd[IS_DISPLAY_NAME_DEFAULT].asBoolean();
 	LLDate expires = sd[DISPLAY_NAME_EXPIRES];
 	mExpires = expires.secondsSinceEpoch();
+	LLDate next_update = sd[DISPLAY_NAME_NEXT_UPDATE];
+	mNextUpdate = next_update.secondsSinceEpoch();
 }
 
 std::string LLAvatarName::getCompleteName() const
diff --git a/indra/llcommon/llavatarname.h b/indra/llcommon/llavatarname.h
index 8b74e006c39..650a09a125e 100644
--- a/indra/llcommon/llavatarname.h
+++ b/indra/llcommon/llavatarname.h
@@ -91,6 +91,11 @@ class LL_COMMON_API LLAvatarName
 	// last checked.
 	// Unix time-from-epoch seconds for efficiency
 	F64 mExpires;
+	
+	// You can only change your name every N hours, so record
+	// when the next update is allowed
+	// Unix time-from-epoch seconds
+	F64 mNextUpdate;
 };
 
 #endif
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp
index b5a73ec1d13..637064d75f3 100644
--- a/indra/llcommon/llstring.cpp
+++ b/indra/llcommon/llstring.cpp
@@ -694,14 +694,17 @@ void LLStringOps::setupDatetimeInfo (bool daylight)
 
 	nowT = time (NULL);
 
-	tmpT = localtime (&nowT);
-	localT = mktime (tmpT);
-
 	tmpT = gmtime (&nowT);
 	gmtT = mktime (tmpT);
 
+	tmpT = localtime (&nowT);
+	localT = mktime (tmpT);
+	
 	sLocalTimeOffset = (long) (gmtT - localT);
-
+	if (tmpT->tm_isdst)
+	{
+		sLocalTimeOffset -= 60 * 60;	// 1 hour
+	}
 
 	sPacificDaylightTime = daylight;
 	sPacificTimeOffset = (sPacificDaylightTime? 7 : 8 ) * 60 * 60;
diff --git a/indra/newview/llpanelme.cpp b/indra/newview/llpanelme.cpp
index 544ca47da40..eb2d57af523 100644
--- a/indra/newview/llpanelme.cpp
+++ b/indra/newview/llpanelme.cpp
@@ -305,11 +305,7 @@ void LLPanelMyProfileEdit::onCacheSetName(bool success,
 	{
 		// Inform the user that the change took place, but will take a while
 		// to percolate.
-		LLSD args;
-		// *TODO: get estimated percolation time from service
-		S32 timeout_hours = 72;
-		args["HOURS"] = llformat("%d", timeout_hours);
-		LLNotificationsUtil::add("SetDisplayNameSuccess", args);
+		LLNotificationsUtil::add("SetDisplayNameSuccess");
 
 		// Re-fetch my name, as it may have been sanitized by the service
 		LLAvatarNameCache::get(getAvatarId(),
@@ -322,6 +318,7 @@ void LLPanelMyProfileEdit::onCacheSetName(bool success,
 	llinfos << "set name failure error_tag " << error_tag << llendl;
 
 	// We might have a localized string for this message
+	// error_args will usually be empty from the server.
 	if (!error_tag.empty()
 		&& LLNotifications::getInstance()->templateExists(error_tag))
 	{
@@ -382,29 +379,46 @@ void LLPanelMyProfileEdit::onDialogSetName(const LLSD& notification, const LLSD&
 
 void LLPanelMyProfileEdit::onClickSetName()
 {
-	// IDEVO
 	LLUUID agent_id = getAvatarId();
 	std::string display_name;
 	LLAvatarName av_name;
-	if (LLAvatarNameCache::useDisplayNames()
-		&& LLAvatarNameCache::get(agent_id, &av_name))
+	if (!LLAvatarNameCache::get(agent_id, &av_name))
 	{
-		display_name = av_name.mDisplayName;
+		// something is wrong, tell user to try again later
+		LLNotificationsUtil::add("SetDisplayNameFailedGeneric");
+		return;
 	}
-	else
+		
+	display_name = av_name.mDisplayName;
+	if (display_name.empty())
 	{
-		gCacheName->getFullName(agent_id, display_name);
+		// something is wrong, tell user to try again later
+		LLNotificationsUtil::add("SetDisplayNameFailedGeneric");
+		return;		
 	}
 
-	if (!display_name.empty())
+	F64 now_secs = LLDate::now().secondsSinceEpoch();
+	if (now_secs < av_name.mNextUpdate)
 	{
+		// ...can't update until some time in the future
+		F64 next_update_local_secs =
+			av_name.mNextUpdate - LLStringOps::getLocalTimeOffset();
+		LLDate next_update_local(next_update_local_secs);
+		// display as "July 18 12:17 PM"
+		std::string next_update_string =
+		next_update_local.toHTTPDateString("%B %d %I:%M %p");
 		LLSD args;
-		args["DISPLAY_NAME"] = display_name;
-		LLSD payload;
-		payload["agent_id"] = agent_id;
-		LLNotificationsUtil::add("SetDisplayName", args, payload, 
-			boost::bind(&LLPanelMyProfileEdit::onDialogSetName, this, _1, _2));
+		args["TIME"] = next_update_string;
+		LLNotificationsUtil::add("SetDisplayNameFailedLockout", args);
+		return;
 	}
+	
+	LLSD args;
+	args["DISPLAY_NAME"] = display_name;
+	LLSD payload;
+	payload["agent_id"] = agent_id;
+	LLNotificationsUtil::add("SetDisplayName", args, payload, 
+		boost::bind(&LLPanelMyProfileEdit::onDialogSetName, this, _1, _2));
 }
 
 void LLPanelMyProfileEdit::enableEditing(bool enable)
diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml
index 51b88cf59ae..904084cfa79 100644
--- a/indra/newview/skins/default/xui/en/notifications.xml
+++ b/indra/newview/skins/default/xui/en/notifications.xml
@@ -3145,9 +3145,11 @@ You are no longer frozen.
    icon="alertmodal.tga"
    name="SetDisplayName"
    type="alertmodal">
-Change your display name (used for name tags, chat, etc.)?
+Your new display name will be used for name tags, chat, friends lists, etc. You can also reset it back to your original username. There will be a delay before you can change your display name again, so choose wisely.
 
-You can also reset it back to your original username.
+See http://wiki.secondlife.com/wiki/Setting_your_display_name
+
+Change your display name?
     <form name="form">
       <input name="display_name" type="text">
 [DISPLAY_NAME]
@@ -3174,9 +3176,19 @@ You can also reset it back to your original username.
    type="alertmodal">
 Thanks for updating your name!
 
-Just like in real life, it takes a while for everyone to learn about a new name.  Please allow [HOURS] hours for your name to update in object ownership, scripts, search, etc.
+Just like in real life, it takes a while for everyone to learn about a new name.  Please allow several days for your name to update in object ownership, scripts, search, etc.
 
-See http://wiki.secondlife.com/wiki/Setting_your_display_name for details.
+See http://wiki.secondlife.com/wiki/Setting_your_display_name
+  </notification>
+
+  <notification
+   icon="alertmodal.tga"
+   name="SetDisplayNameFailedLockout"
+   type="alertmodal">
+Sorry, you cannot change your display name until:
+[TIME]
+
+See http://wiki.secondlife.com/wiki/Setting_your_display_name
   </notification>
 
   <notification
@@ -3195,11 +3207,14 @@ Please try a shorter name.
     Sorry, we could not set your display name.  Please try again later.
   </notification>
 
+<!-- *NOTE: This should never happen, users should see SetDisplayNameFailedLockout above -->
   <notification
    icon="alertmodal.tga"
    name="AgentDisplayNameUpdateThresholdExceeded"
    type="alertmodal">
-Sorry, you can only change your name once every 24 hours.
+Sorry, you have to wait longer before you can change your display name.
+
+See http://wiki.secondlife.com/wiki/Setting_your_display_name for details.
 
 Please try again later.
   </notification>
-- 
GitLab