From e14a641619afc9948b590c2caf8df8df02bdbfe3 Mon Sep 17 00:00:00 2001
From: James Cook <james@lindenlab.com>
Date: Tue, 16 Feb 2010 17:18:36 -0800
Subject: [PATCH] DEV-46234 Group Invite contains SLID with Resident, and
 DEV-46231 Pay resident notification contains SLID with Resident last name,
 and DEV-46232 Payment confirmation of buy and sell parcel of land contains
 SLID with Resident in both notifications Clean up server-side name strings
 with regex matching. Reviewed with Simon.

---
 indra/llinventory/lltransactionflags.cpp      |  6 ++
 indra/newview/llnotificationhandlerutil.cpp   |  8 +-
 indra/newview/llviewermessage.cpp             | 99 ++++++++++++++-----
 .../skins/default/xui/en/notifications.xml    | 20 +++-
 4 files changed, 101 insertions(+), 32 deletions(-)

diff --git a/indra/llinventory/lltransactionflags.cpp b/indra/llinventory/lltransactionflags.cpp
index e0f87aa7db7..79f8589bb14 100644
--- a/indra/llinventory/lltransactionflags.cpp
+++ b/indra/llinventory/lltransactionflags.cpp
@@ -114,6 +114,9 @@ std::string build_transfer_message_to_source(
 	std::ostringstream ostr;
 	if(dest_id.isNull())
 	{
+		// *NOTE: Do not change these strings!  The viewer matches
+		// them in llviewermessage.cpp to perform localization.
+		// If you need to make changes, add a new, localizable message. JC
 		ostr << "You paid L$" << amount;
 		switch(transaction_type)
 		{
@@ -160,6 +163,9 @@ std::string build_transfer_message_to_destination(
 		return description;
 	}
 	std::ostringstream ostr;
+	// *NOTE: Do not change these strings!  The viewer matches
+	// them in llviewermessage.cpp to perform localization.
+	// If you need to make changes, add a new, localizable message. JC
 	ostr << source_name << " paid you L$" << amount;
 	append_reason(ostr, transaction_type, description);
 	ostr << ".";
diff --git a/indra/newview/llnotificationhandlerutil.cpp b/indra/newview/llnotificationhandlerutil.cpp
index 4d1a8fcb041..9c60483416e 100644
--- a/indra/newview/llnotificationhandlerutil.cpp
+++ b/indra/newview/llnotificationhandlerutil.cpp
@@ -46,7 +46,9 @@ using namespace LLNotificationsUI;
 const static std::string GRANTED_MODIFY_RIGHTS("GrantedModifyRights"),
 		REVOKED_MODIFY_RIGHTS("RevokedModifyRights"), OBJECT_GIVE_ITEM(
 				"ObjectGiveItem"),
-						PAYMENT_RECIVED("PaymentRecived"),
+						PAYMENT_RECEIVED("PaymentReceived"),
+						PAYMENT_RECEIVED_FOR("PaymentReceivedFor"),
+						PAYMENT_SENT("PaymentSent"),
 						ADD_FRIEND_WITH_MESSAGE("AddFriendWithMessage"),
 						USER_GIVE_ITEM("UserGiveItem"),
 						INVENTORY_ACCEPTED("InventoryAccepted"),
@@ -63,7 +65,9 @@ bool LLHandlerUtil::canLogToIM(const LLNotificationPtr& notification)
 {
 	return GRANTED_MODIFY_RIGHTS == notification->getName()
 			|| REVOKED_MODIFY_RIGHTS == notification->getName()
-			|| PAYMENT_RECIVED == notification->getName()
+			|| PAYMENT_RECEIVED == notification->getName()
+			|| PAYMENT_RECEIVED_FOR == notification->getName()
+			|| PAYMENT_SENT == notification->getName()
 			|| OFFER_FRIENDSHIP == notification->getName()
 			|| FRIENDSHIP_OFFERED == notification->getName()
 			|| SERVER_OBJECT_MESSAGE == notification->getName()
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index 10d5d002cda..f8da6eab3d8 100644
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -105,6 +105,7 @@
 #include "llpanelplaceprofile.h"
 
 #include <boost/algorithm/string/split.hpp> //
+#include <boost/regex.hpp>
 
 #if LL_WINDOWS // For Windows specific error handler
 #include "llwindebug.h"	// For the invalid message handler
@@ -2038,6 +2039,15 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
 				invite_bucket = (struct invite_bucket_t*) &binary_bucket[0];
 				S32 membership_fee = ntohl(invite_bucket->membership_fee);
 
+				// IDEVO Clean up legacy name "Resident" in message constructed in
+				// lldatagroups.cpp
+				U32 pos = message.find(" has invited you to join a group.\n");
+				if (pos != std::string::npos)
+				{
+					// use cleaned-up name from above
+					message = name + message.substr(pos);
+				}
+
 				LLSD payload;
 				payload["transaction_id"] = session_id;
 				payload["group_id"] = from_id;
@@ -4439,6 +4449,67 @@ void process_time_dilation(LLMessageSystem *msg, void **user_data)
 */
 
 
+static void show_money_balance_notification(const std::string& desc)
+{
+	// Intercept some messages constructed in lltransactionflags.cpp
+	// to fix avatar names and allow localization.
+	LLSD args;
+	LLSD payload;
+	std::string name;
+	boost::smatch match;
+	const char* notification_name = NULL;
+
+	// <name> paid you L$<amount> for <reason>.
+	static const boost::regex paid_you_for("(.+) paid you L\\$(\\d+) for (.*)\\.");
+	// <name> paid you L$<amount>.
+	static const boost::regex paid_you("(.+) paid you L\\$(\\d+)\\.");
+	// You paid <name> L$<amount> [for <reason>].
+	static const boost::regex you_paid("You paid (.*) L\\$(\\d+)(.+)\\.");
+
+	if (boost::regex_match(desc, match, paid_you_for))
+	{
+		name = match[1].str();
+		// IDEVO strip legacy "Resident" name
+		name = name.substr(0, name.find(" Resident"));
+		args["NAME"] = name;
+		args["AMOUNT"] = match[2].str();
+		args["REASON"] = match[3].str();
+		notification_name = "PaymentReceivedFor";
+	}
+	else if (boost::regex_match(desc, match, paid_you))
+	{
+		name = match[1].str();
+		// IDEVO strip legacy "Resident" name
+		name = name.substr(0, name.find(" Resident"));
+		args["NAME"] = name;
+		args["AMOUNT"] = match[2].str();
+		notification_name = "PaymentReceived";
+	}
+	else if (boost::regex_match(desc, match, you_paid))
+	{
+		name = match[1].str();
+		// IDEVO strip legacy "Resident" name
+		name = name.substr(0, name.find(" Resident"));
+		args["NAME"] = name;
+		args["AMOUNT"] = match[2].str();
+		args["REASON"] = match[3].str();
+		notification_name = "PaymentSent";
+	}
+
+	// if name extracted and name cache contains avatar id send loggable notification
+	LLUUID from_id;
+	if (notification_name != NULL
+		&& gCacheName->getUUID(name, from_id))
+	{
+		payload["from_id"] = from_id;
+		LLNotificationsUtil::add(notification_name, args, payload);
+	}
+	else
+	{
+		args["MESSAGE"] = desc;
+		LLNotificationsUtil::add("SystemMessage", args);
+	}
+}
 
 void process_money_balance_reply( LLMessageSystem* msg, void** )
 {
@@ -4483,33 +4554,7 @@ void process_money_balance_reply( LLMessageSystem* msg, void** )
 	if(!desc.empty() && gSavedSettings.getBOOL("NotifyMoneyChange")
 	   && (std::find(recent.rbegin(), recent.rend(), tid) == recent.rend()))
 	{
-		// Make the user confirm the transaction, since they might
-		// have missed something during an event.
-		// *TODO: Translate
-		LLSD args;
-		args["MESSAGE"] = desc;
-
-		// this is a marker to retrieve avatar name from server message:
-		// "<avatar name> paid you L$"
-		const std::string marker = "paid you L$";
-
-		// extract avatar name from system message
-		std::string name = desc.substr(0, desc.find(marker, 0));
-		LLStringUtil::trim(name);
-
-		// if name extracted and name cache contains avatar id send loggable notification
-		LLUUID from_id;
-		if(name.size() > 0 && gCacheName->getUUID(name, from_id))
-		{
-			args["NAME"] = name;
-			LLSD payload;
-			payload["from_id"] = from_id;
-			LLNotificationsUtil::add("PaymentRecived", args, payload);
-		}
-		else
-		{
-			LLNotificationsUtil::add("SystemMessage", args);
-		}
+		show_money_balance_notification(desc);
 
 		// Once the 'recent' container gets large enough, chop some
 		// off the beginning.
diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml
index 665a49b6d89..a69d9c78a7c 100644
--- a/indra/newview/skins/default/xui/en/notifications.xml
+++ b/indra/newview/skins/default/xui/en/notifications.xml
@@ -4621,11 +4621,25 @@ Please select at least one type of content to search (General, Moderate, or Adul
 
   <notification
    icon="notify.tga"
-   name="PaymentRecived"
+   name="PaymentReceived"
    type="notify">
-[MESSAGE]
+[NAME] paid you L$[AMOUNT].
   </notification>
-  
+
+  <notification
+   icon="notify.tga"
+   name="PaymentReceivedFor"
+   type="notify">
+[NAME] paid you L$[AMOUNT] for [REASON].
+  </notification>
+
+  <notification
+   icon="notify.tga"
+   name="PaymentSent"
+   type="notify">
+You paid [NAME] L$[AMOUNT][REASON].
+  </notification>
+
   <notification
    icon="notify.tga"
    name="EventNotification"
-- 
GitLab