From efa716b5fcaa0f0faa4003e072747898a223e983 Mon Sep 17 00:00:00 2001
From: andreykproductengine <akleshchev@productengine.com>
Date: Wed, 18 May 2016 19:29:31 +0300
Subject: [PATCH] MAINT-2129 "Block" button doesn't become disabled

---
 indra/llui/lltextbase.cpp                     | 24 +++++++++++++++++++
 indra/llui/lltextbase.h                       |  3 +++
 indra/llui/llurlaction.cpp                    | 10 ++++++++
 indra/llui/llurlaction.h                      |  1 +
 indra/newview/llchathistory.cpp               | 14 +++++++++--
 indra/newview/llpanelprofile.cpp              | 10 ++++++++
 indra/newview/lltoastnotifypanel.cpp          |  1 +
 .../skins/default/xui/en/menu_object_icon.xml | 15 ++++++++++--
 .../default/xui/en/menu_url_objectim.xml      |  7 ++++++
 9 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index 616c42895cd..3e4680de249 100644
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -177,6 +177,7 @@ LLTextBase::LLTextBase(const LLTextBase::Params &p)
 :	LLUICtrl(p, LLTextViewModelPtr(new LLTextViewModel)),
 	mURLClickSignal(NULL),
 	mIsFriendSignal(NULL),
+	mIsObjectBlockedSignal(NULL),
 	mMaxTextByteLength( p.max_text_length ),
 	mFont(p.font),
 	mFontShadow(p.font_shadow),
@@ -1942,6 +1943,7 @@ void LLTextBase::createUrlContextMenu(S32 x, S32 y, const std::string &in_url)
 	registrar.add("Url.OpenExternal", boost::bind(&LLUrlAction::openURLExternal, url));
 	registrar.add("Url.Execute", boost::bind(&LLUrlAction::executeSLURL, url, true));
 	registrar.add("Url.Block", boost::bind(&LLUrlAction::blockObject, url));
+	registrar.add("Url.Unblock", boost::bind(&LLUrlAction::unblockObject, 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));
@@ -1968,6 +1970,19 @@ void LLTextBase::createUrlContextMenu(S32 x, S32 y, const std::string &in_url)
 			removeFriendButton->setEnabled(isFriend);
 		}
 	}
+
+	if (mIsObjectBlockedSignal)
+	{
+		bool is_blocked = *(*mIsObjectBlockedSignal)(LLUUID(LLUrlAction::getObjectId(url)), LLUrlAction::getObjectName(url));
+		LLView* blockButton = mPopupMenu->getChild<LLView>("block_object");
+		LLView* unblockButton = mPopupMenu->getChild<LLView>("unblock_object");
+
+		if (blockButton && unblockButton)
+		{
+			blockButton->setVisible(!is_blocked);
+			unblockButton->setVisible(is_blocked);
+		}
+	}
 	
 	if (mPopupMenu)
 	{
@@ -3022,6 +3037,15 @@ boost::signals2::connection LLTextBase::setIsFriendCallback(const is_friend_sign
 	return mIsFriendSignal->connect(cb);
 }
 
+boost::signals2::connection LLTextBase::setIsObjectBlockedCallback(const is_blocked_signal_t::slot_type& cb)
+{
+    if (!mIsObjectBlockedSignal)
+    {
+        mIsObjectBlockedSignal = new is_blocked_signal_t();
+    }
+    return mIsObjectBlockedSignal->connect(cb);
+}
+
 //
 // LLTextSegment
 //
diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h
index c6ce5efcb8f..85641fd8992 100644
--- a/indra/llui/lltextbase.h
+++ b/indra/llui/lltextbase.h
@@ -270,6 +270,7 @@ class LLTextBase
 	friend class LLUICtrlFactory;
 
 	typedef boost::signals2::signal<bool (const LLUUID& user_id)> is_friend_signal_t;
+	typedef boost::signals2::signal<bool (const LLUUID& blocked_id, const std::string from)> is_blocked_signal_t;
 
 	struct LineSpacingParams : public LLInitParam::ChoiceBlock<LineSpacingParams>
 	{
@@ -456,6 +457,7 @@ class LLTextBase
 	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);
+	boost::signals2::connection setIsObjectBlockedCallback(const is_blocked_signal_t::slot_type& cb);
 
 	void					setWordWrap(bool wrap);
 	LLScrollContainer*		getScrollContainer() const { return mScroller; }
@@ -685,6 +687,7 @@ class LLTextBase
 
 	// Used to check if user with given ID is avatar's friend
 	is_friend_signal_t*         mIsFriendSignal;
+	is_blocked_signal_t*        mIsObjectBlockedSignal;
 
 	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 56977c597b3..84ea770a8d8 100644
--- a/indra/llui/llurlaction.cpp
+++ b/indra/llui/llurlaction.cpp
@@ -231,3 +231,13 @@ void LLUrlAction::blockObject(std::string url)
 		executeSLURL("secondlife:///app/agent/" + object_id + "/block/" + LLURI::escape(object_name));
 	}
 }
+
+void LLUrlAction::unblockObject(std::string url)
+{
+    std::string object_id = getObjectId(url);
+    std::string object_name = getObjectName(url);
+    if (LLUUID::validate(object_id))
+    {
+        executeSLURL("secondlife:///app/agent/" + object_id + "/unblock/" + object_name);
+    }
+}
diff --git a/indra/llui/llurlaction.h b/indra/llui/llurlaction.h
index 5497e28bb43..2d2a8dfef19 100644
--- a/indra/llui/llurlaction.h
+++ b/indra/llui/llurlaction.h
@@ -83,6 +83,7 @@ class LLUrlAction
 	static void addFriend(std::string url);
 	static void removeFriend(std::string url);
 	static void blockObject(std::string url);
+	static void unblockObject(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/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp
index 95649519861..5d2997688fc 100644
--- a/indra/newview/llchathistory.cpp
+++ b/indra/newview/llchathistory.cpp
@@ -156,6 +156,10 @@ class LLChatHistoryHeader: public LLPanel
 			LLFloaterSidePanelContainer::showPanel("people", "panel_people",
 				LLSD().with("people_panel_tab_name", "blocked_panel").with("blocked_to_select", getAvatarId()));
 		}
+		else if (level == "unblock")
+		{
+			LLMuteList::getInstance()->remove(LLMute(getAvatarId(), mFrom, LLMute::OBJECT));
+		}
 		else if (level == "map")
 		{
 			std::string url = "secondlife://" + mObjectData["slurl"].asString();
@@ -169,10 +173,14 @@ class LLChatHistoryHeader: public LLPanel
 
 	}
 
-    bool onObjectIconContextMenuItemEnabled(const LLSD& userdata)
+    bool onObjectIconContextMenuItemVisible(const LLSD& userdata)
     {
         std::string level = userdata.asString();
         if (level == "is_blocked")
+        {
+            return LLMuteList::getInstance()->isMuted(getAvatarId(), mFrom, LLMute::flagTextChat);
+        }
+        else if (level == "not_blocked")
         {
             return !LLMuteList::getInstance()->isMuted(getAvatarId(), mFrom, LLMute::flagTextChat);
         }
@@ -285,7 +293,7 @@ class LLChatHistoryHeader: public LLPanel
 		registrar.add("AvatarIcon.Action", boost::bind(&LLChatHistoryHeader::onAvatarIconContextMenuItemClicked, this, _2));
 		registrar_enable.add("AvatarIcon.Check", boost::bind(&LLChatHistoryHeader::onAvatarIconContextMenuItemChecked, this, _2));
 		registrar.add("ObjectIcon.Action", boost::bind(&LLChatHistoryHeader::onObjectIconContextMenuItemClicked, this, _2));
-		registrar_enable.add("ObjectIcon.Enable", boost::bind(&LLChatHistoryHeader::onObjectIconContextMenuItemEnabled, this, _2));
+		registrar_enable.add("ObjectIcon.Visible", boost::bind(&LLChatHistoryHeader::onObjectIconContextMenuItemVisible, this, _2));
 
 		LLMenuGL* menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_avatar_icon.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
 		mPopupMenuHandleAvatar = menu->getHandle();
@@ -730,6 +738,8 @@ LLChatHistory::LLChatHistory(const LLChatHistory::Params& p)
 	editor_params.trusted_content = false;
 	mEditor = LLUICtrlFactory::create<LLTextEditor>(editor_params, this);
 	mEditor->setIsFriendCallback(LLAvatarActions::isFriend);
+	mEditor->setIsObjectBlockedCallback(boost::bind(&LLMuteList::isMuted, LLMuteList::getInstance(), _1, _2, 0));
+
 }
 
 LLSD LLChatHistory::getValue() const
diff --git a/indra/newview/llpanelprofile.cpp b/indra/newview/llpanelprofile.cpp
index e795e7eedb0..184238c40ca 100644
--- a/indra/newview/llpanelprofile.cpp
+++ b/indra/newview/llpanelprofile.cpp
@@ -176,6 +176,16 @@ class LLAgentHandler : public LLCommandHandler
 			return true;
 		}
 
+		if (verb == "unblock")
+		{
+			if (params.size() > 2)
+			{
+				const std::string object_name = params[2].asString();
+				LLMute mute(avatar_id, object_name, LLMute::OBJECT);
+				LLMuteList::getInstance()->remove(mute);
+			}
+			return true;
+		}
 		return false;
 	}
 };
diff --git a/indra/newview/lltoastnotifypanel.cpp b/indra/newview/lltoastnotifypanel.cpp
index 1a8ade5b102..e3a856be5cd 100644
--- a/indra/newview/lltoastnotifypanel.cpp
+++ b/indra/newview/lltoastnotifypanel.cpp
@@ -325,6 +325,7 @@ void LLToastNotifyPanel::init( LLRect rect, bool show_images )
     mTextBox->setContentTrusted(is_content_trusted);
     mTextBox->setValue(mNotification->getMessage());
 	mTextBox->setIsFriendCallback(LLAvatarActions::isFriend);
+    mTextBox->setIsObjectBlockedCallback(boost::bind(&LLMuteList::isMuted, LLMuteList::getInstance(), _1, _2, 0));
 
     // add buttons for a script notification
     if (mIsTip)
diff --git a/indra/newview/skins/default/xui/en/menu_object_icon.xml b/indra/newview/skins/default/xui/en/menu_object_icon.xml
index 93093014eb1..5137aea72ac 100644
--- a/indra/newview/skins/default/xui/en/menu_object_icon.xml
+++ b/indra/newview/skins/default/xui/en/menu_object_icon.xml
@@ -23,8 +23,19 @@
         <menu_item_call.on_click
          function="ObjectIcon.Action"
          parameter="block" />
-        <menu_item_call.on_enable
-         function="ObjectIcon.Enable"
+        <menu_item_call.on_visible
+         function="ObjectIcon.Visible"
+         parameter="not_blocked" />
+    </menu_item_call>
+    <menu_item_call
+     label="Unblock"
+     layout="topleft"
+     name="Unblock">
+        <menu_item_call.on_click
+         function="ObjectIcon.Action"
+         parameter="unblock" />
+        <menu_item_call.on_visible
+         function="ObjectIcon.Visible"
          parameter="is_blocked" />
     </menu_item_call>
     <menu_item_separator
diff --git a/indra/newview/skins/default/xui/en/menu_url_objectim.xml b/indra/newview/skins/default/xui/en/menu_url_objectim.xml
index b9d003b8419..41d40b389a6 100644
--- a/indra/newview/skins/default/xui/en/menu_url_objectim.xml
+++ b/indra/newview/skins/default/xui/en/menu_url_objectim.xml
@@ -16,6 +16,13 @@
         <menu_item_call.on_click
          function="Url.Block" />
     </menu_item_call>
+    <menu_item_call
+     label="Unblock"
+     layout="topleft"
+     name="unblock_object">
+        <menu_item_call.on_click
+         function="Url.Unblock" />
+    </menu_item_call>
     <menu_item_separator
      layout="topleft" />
     <menu_item_call
-- 
GitLab