From 882ab04ef3e412716f0f034e348007b5f3016f3c Mon Sep 17 00:00:00 2001
From: mberezhnoy <mberezhnoy@productengine.com>
Date: Thu, 13 Jun 2013 20:21:24 +0300
Subject: [PATCH] CHUI-809 (Right-click menu on user name in compat chat mode
 doesn't have "IM") Added callback for friendship checking

---
 indra/llui/lltextbase.cpp                     | 24 +++++++++++++++++++
 indra/llui/lltextbase.h                       |  6 +++++
 indra/llui/llurlaction.cpp                    |  8 +++++++
 indra/llui/llurlaction.h                      |  1 +
 indra/llui/llurlentry.cpp                     |  4 ++++
 indra/newview/llchathistory.cpp               |  1 +
 indra/newview/llpanelprofile.cpp              |  6 +++++
 .../skins/default/xui/en/menu_url_agent.xml   |  9 ++++++-
 .../newview/skins/default/xui/en/strings.xml  |  3 ++-
 9 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index a53a38124cb..e2a39d89e4b 100755
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -180,6 +180,7 @@ LLTextBase::Params::Params()
 LLTextBase::LLTextBase(const LLTextBase::Params &p) 
 :	LLUICtrl(p, LLTextViewModelPtr(new LLTextViewModel)),
 	mURLClickSignal(NULL),
+	mIsFriendSignal(NULL),
 	mMaxTextByteLength( p.max_text_length ),
 	mFont(p.font),
 	mFontShadow(p.font_shadow),
@@ -1943,6 +1944,7 @@ void LLTextBase::createUrlContextMenu(S32 x, S32 y, const std::string &in_url)
 	registrar.add("Url.Teleport", boost::bind(&LLUrlAction::teleportToLocation, url));
 	registrar.add("Url.ShowProfile", boost::bind(&LLUrlAction::showProfile, url));
 	registrar.add("Url.AddFriend", boost::bind(&LLUrlAction::addFriend, url));
+	registrar.add("Url.RemoveFriend", boost::bind(&LLUrlAction::removeFriend, url));
 	registrar.add("Url.SendIM", boost::bind(&LLUrlAction::sendIM, url));
 	registrar.add("Url.ShowOnMap", boost::bind(&LLUrlAction::showLocationOnMap, url));
 	registrar.add("Url.CopyLabel", boost::bind(&LLUrlAction::copyLabelToClipboard, url));
@@ -1952,6 +1954,19 @@ void LLTextBase::createUrlContextMenu(S32 x, S32 y, const std::string &in_url)
 	delete mPopupMenu;
 	mPopupMenu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu>(xui_file, LLMenuGL::sMenuContainer,
 																		 LLMenuHolderGL::child_registry_t::instance());	
+	if (mIsFriendSignal)
+	{
+		bool isFriend = (*mIsFriendSignal)(LLUUID(LLUrlAction::getUserID(url)));
+		LLView* addFriendButton = mPopupMenu->getChild<LLView>("add_friend");
+		LLView* removeFriendButton = mPopupMenu->getChild<LLView>("remove_friend");
+
+		if (addFriendButton && removeFriendButton)
+		{
+			addFriendButton->setEnabled(!isFriend);
+			removeFriendButton->setEnabled(isFriend);
+		}
+	}
+	
 	if (mPopupMenu)
 	{
 		mPopupMenu->show(x, y);
@@ -2932,6 +2947,15 @@ boost::signals2::connection LLTextBase::setURLClickedCallback(const commit_signa
 	return mURLClickSignal->connect(cb);
 }
 
+boost::signals2::connection LLTextBase::setIsFriendCallback(const is_friend_signal_t::slot_type& cb)
+{
+	if (!mIsFriendSignal)
+	{
+		mIsFriendSignal = new is_friend_signal_t();
+	}
+	return mIsFriendSignal->connect(cb);
+}
+
 //
 // LLTextSegment
 //
diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h
index 2fb58d468aa..a74e97cac83 100755
--- a/indra/llui/lltextbase.h
+++ b/indra/llui/lltextbase.h
@@ -258,6 +258,8 @@ class LLTextBase
 	friend class LLNormalTextSegment;
 	friend class LLUICtrlFactory;
 
+	typedef boost::signals2::signal<bool (const LLUUID& user_id)> is_friend_signal_t;
+
 	struct LineSpacingParams : public LLInitParam::ChoiceBlock<LineSpacingParams>
 	{
 		Alternative<F32>	multiple;
@@ -434,6 +436,7 @@ class LLTextBase
 	virtual void			appendImageSegment(const LLStyle::Params& style_params);
 	virtual void			appendWidget(const LLInlineViewSegment::Params& params, const std::string& text, bool allow_undo);
 	boost::signals2::connection setURLClickedCallback(const commit_signal_t::slot_type& cb);
+	boost::signals2::connection setIsFriendCallback(const is_friend_signal_t::slot_type& cb);
 
 	void					setWordWrap(bool wrap);
 	LLScrollContainer*		getScrollContainer() const { return mScroller; }
@@ -648,6 +651,9 @@ class LLTextBase
 	// Fired when a URL link is clicked
 	commit_signal_t*			mURLClickSignal;
 
+	// Used to check if user with given ID is avatar's friend
+	is_friend_signal_t*         mIsFriendSignal;
+
 	LLUIString					mLabel;	// text label that is visible when no user text provided
 };
 
diff --git a/indra/llui/llurlaction.cpp b/indra/llui/llurlaction.cpp
index f51aeaec131..cf707d87dc3 100755
--- a/indra/llui/llurlaction.cpp
+++ b/indra/llui/llurlaction.cpp
@@ -188,3 +188,11 @@ void LLUrlAction::addFriend(std::string url)
 	}
 }
 
+void LLUrlAction::removeFriend(std::string url)
+{
+	std::string id_str = getUserID(url);
+	if (LLUUID::validate(id_str))
+	{
+		executeSLURL("secondlife:///app/agent/" + id_str + "/removefriend");
+	}
+}
diff --git a/indra/llui/llurlaction.h b/indra/llui/llurlaction.h
index e31cd71a207..65283394a0a 100755
--- a/indra/llui/llurlaction.h
+++ b/indra/llui/llurlaction.h
@@ -79,6 +79,7 @@ class LLUrlAction
 	static std::string getUserID(std::string url);
 	static void sendIM(std::string url);
 	static void addFriend(std::string url);
+	static void LLUrlAction::removeFriend(std::string url);
 
 	/// specify the callbacks to enable this class's functionality
 	typedef boost::function<void (const std::string&)> url_callback_t;
diff --git a/indra/llui/llurlentry.cpp b/indra/llui/llurlentry.cpp
index 99ee6888889..b1cc502c4bb 100755
--- a/indra/llui/llurlentry.cpp
+++ b/indra/llui/llurlentry.cpp
@@ -504,6 +504,10 @@ std::string localize_slapp_label(const std::string& url, const std::string& full
 	{
 		return LLTrans::getString("SLappAgentRequestFriend") + " " + full_name;
 	}
+	if (LLStringUtil::endsWith(url, "/removefriend"))
+	{
+		return LLTrans::getString("SLappAgentRemoveFriend") + " " + full_name;
+	}
 	return full_name;
 }
 
diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp
index 0f138873ac8..af3c6eff116 100755
--- a/indra/newview/llchathistory.cpp
+++ b/indra/newview/llchathistory.cpp
@@ -628,6 +628,7 @@ LLChatHistory::LLChatHistory(const LLChatHistory::Params& p)
 	editor_params.enabled = false; // read only
 	editor_params.show_context_menu = "true";
 	mEditor = LLUICtrlFactory::create<LLTextEditor>(editor_params, this);
+	mEditor->setIsFriendCallback(LLAvatarActions::isFriend);
 }
 
 LLSD LLChatHistory::getValue() const
diff --git a/indra/newview/llpanelprofile.cpp b/indra/newview/llpanelprofile.cpp
index e2e70067737..3b95b464767 100755
--- a/indra/newview/llpanelprofile.cpp
+++ b/indra/newview/llpanelprofile.cpp
@@ -137,6 +137,12 @@ class LLAgentHandler : public LLCommandHandler
 			return true;
 		}
 
+		if (verb == "removefriend")
+		{
+			LLAvatarActions::removeFriendDialog(avatar_id);
+			return true;
+		}
+
 		if (verb == "mute")
 		{
 			if (! LLAvatarActions::isBlocked(avatar_id))
diff --git a/indra/newview/skins/default/xui/en/menu_url_agent.xml b/indra/newview/skins/default/xui/en/menu_url_agent.xml
index 7cd56f257a8..e8b6116026a 100755
--- a/indra/newview/skins/default/xui/en/menu_url_agent.xml
+++ b/indra/newview/skins/default/xui/en/menu_url_agent.xml
@@ -21,8 +21,15 @@
      layout="topleft"
      name="add_friend">
         <menu_item_call.on_click
-         function="Url.AddFriend" />        
+         function="Url.AddFriend" />
     </menu_item_call>
+    <menu_item_call
+     label="Remove Friend..."
+     layout="topleft"
+     name="remove_friend">
+        <menu_item_call.on_click
+         function="Url.RemoveFriend" />
+        </menu_item_call>
     <menu_item_separator
      layout="topleft" />
     <menu_item_call
diff --git a/indra/newview/skins/default/xui/en/strings.xml b/indra/newview/skins/default/xui/en/strings.xml
index 3b57ff5fd67..521aed698a9 100755
--- a/indra/newview/skins/default/xui/en/strings.xml
+++ b/indra/newview/skins/default/xui/en/strings.xml
@@ -209,7 +209,8 @@ Please try logging in again in a minute.</string>
 	<string name="SLappAgentIM">IM</string>
 	<string name="SLappAgentPay">Pay</string>
 	<string name="SLappAgentOfferTeleport">Offer Teleport to </string>
-	<string name="SLappAgentRequestFriend">Friend Request </string>
+	<string name="SLappAgentRequestFriend">Friend Request</string>
+  <string name="SLappAgentRemoveFriend">Friend Removal</string>
 
 	<!-- ButtonToolTips, llfloater.cpp -->
 	<string name="BUTTON_CLOSE_DARWIN">Close (&#8984;W)</string>
-- 
GitLab