From d5d9668a59895874951fb3e5927ea0159270a6e8 Mon Sep 17 00:00:00 2001
From: Paul Guslisty <pguslisty@productengine.com>
Date: Thu, 25 Mar 2010 09:04:01 +0200
Subject: [PATCH] Fixed low bug EXT-6488 (Teleport menuitem is enabled for
 offline residents in the context menu and inspectors)

- Added a check for a teleport offer ability. In XML created a paremeter and check it in source code.

Reviewed by Leyla Farazha at https://codereview.productengine.com/secondlife/r/86/

--HG--
branch : product-engine
---
 indra/newview/llavataractions.cpp                  | 14 ++++++++++++++
 indra/newview/llavataractions.h                    |  6 ++++++
 indra/newview/llinspectavatar.cpp                  |  7 +++++++
 indra/newview/llpanelpeoplemenus.cpp               |  5 +++++
 .../default/xui/en/menu_inspect_avatar_gear.xml    |  2 ++
 .../skins/default/xui/en/menu_people_nearby.xml    |  3 +++
 6 files changed, 37 insertions(+)

diff --git a/indra/newview/llavataractions.cpp b/indra/newview/llavataractions.cpp
index cb518f0ad6a..699916b0d6c 100644
--- a/indra/newview/llavataractions.cpp
+++ b/indra/newview/llavataractions.cpp
@@ -442,6 +442,20 @@ void LLAvatarActions::toggleBlock(const LLUUID& id)
 		LLMuteList::getInstance()->add(mute);
 	}
 }
+// static
+bool LLAvatarActions::canOfferTeleport(const LLUUID& id)
+{
+	// First use LLAvatarTracker::isBuddy()
+	// If LLAvatarTracker::instance().isBuddyOnline function only is used
+	// then for avatars that are online and not a friend it will return false.
+	// But we should give an ability to offer a teleport for such avatars.
+	if(LLAvatarTracker::instance().isBuddy(id))
+	{
+		return LLAvatarTracker::instance().isBuddyOnline(id);
+	}
+
+	return true;
+}
 
 void LLAvatarActions::inviteToGroup(const LLUUID& id)
 {
diff --git a/indra/newview/llavataractions.h b/indra/newview/llavataractions.h
index a7f3acad4f8..9adf6efec72 100644
--- a/indra/newview/llavataractions.h
+++ b/indra/newview/llavataractions.h
@@ -171,6 +171,12 @@ class LLAvatarActions
 	 */	
 	static void csr(const LLUUID& id, std::string name);
 
+	/**
+	 * Checks whether can offer teleport to the avatar
+	 * Can't offer only for offline friends
+	 */
+	static bool canOfferTeleport(const LLUUID& id);
+
 	
 private:
 	static bool callbackAddFriend(const LLSD& notification, const LLSD& response);
diff --git a/indra/newview/llinspectavatar.cpp b/indra/newview/llinspectavatar.cpp
index 35cb9b3468c..94ea2367572 100644
--- a/indra/newview/llinspectavatar.cpp
+++ b/indra/newview/llinspectavatar.cpp
@@ -137,6 +137,7 @@ class LLInspectAvatar : public LLInspect, LLTransientFloater
 	void onVolumeChange(const LLSD& data);
 	bool enableMute();
 	bool enableUnmute();
+	bool enableTeleportOffer();
 
 	// Is used to determine if "Add friend" option should be enabled in gear menu
 	bool isNotFriend();
@@ -235,6 +236,7 @@ LLInspectAvatar::LLInspectAvatar(const LLSD& sd)
 		boost::bind(&LLInspectAvatar::onVisibleZoomIn, this));
 	mEnableCallbackRegistrar.add("InspectAvatar.Gear.Enable", boost::bind(&LLInspectAvatar::isNotFriend, this));
 	mEnableCallbackRegistrar.add("InspectAvatar.Gear.EnableCall", boost::bind(&LLAvatarActions::canCall));
+	mEnableCallbackRegistrar.add("InspectAvatar.Gear.EnableTeleportOffer", boost::bind(&LLInspectAvatar::enableTeleportOffer, this));
 	mEnableCallbackRegistrar.add("InspectAvatar.EnableMute", boost::bind(&LLInspectAvatar::enableMute, this));
 	mEnableCallbackRegistrar.add("InspectAvatar.EnableUnmute", boost::bind(&LLInspectAvatar::enableUnmute, this));
 
@@ -764,6 +766,11 @@ bool LLInspectAvatar::enableUnmute()
 		}
 }
 
+bool LLInspectAvatar::enableTeleportOffer()
+{
+	return LLAvatarActions::canOfferTeleport(mAvatarID);
+}
+
 //////////////////////////////////////////////////////////////////////////////
 // LLInspectAvatarUtil
 //////////////////////////////////////////////////////////////////////////////
diff --git a/indra/newview/llpanelpeoplemenus.cpp b/indra/newview/llpanelpeoplemenus.cpp
index 854651cd019..313ed4b70e0 100644
--- a/indra/newview/llpanelpeoplemenus.cpp
+++ b/indra/newview/llpanelpeoplemenus.cpp
@@ -226,6 +226,11 @@ bool NearbyMenu::enableContextMenuItem(const LLSD& userdata)
 		return (LLAvatarTracker::instance().isBuddyOnline(id) && is_agent_mappable(id))
 					|| gAgent.isGodlike();
 	}
+	else if(item == std::string("can_offer_teleport"))
+	{
+		const LLUUID& id = mUUIDs.front();
+		return LLAvatarActions::canOfferTeleport(id);
+	}
 	return false;
 }
 
diff --git a/indra/newview/skins/default/xui/en/menu_inspect_avatar_gear.xml b/indra/newview/skins/default/xui/en/menu_inspect_avatar_gear.xml
index 1b002b1c320..a5ac5f76e1f 100644
--- a/indra/newview/skins/default/xui/en/menu_inspect_avatar_gear.xml
+++ b/indra/newview/skins/default/xui/en/menu_inspect_avatar_gear.xml
@@ -40,6 +40,8 @@
    name="teleport">
     <menu_item_call.on_click
      function="InspectAvatar.Teleport"/>
+    <menu_item_call.on_enable
+     function="InspectAvatar.Gear.EnableTeleportOffer"/>
   </menu_item_call>
   <menu_item_call
    label="Invite to Group"
diff --git a/indra/newview/skins/default/xui/en/menu_people_nearby.xml b/indra/newview/skins/default/xui/en/menu_people_nearby.xml
index 014a52bb4ff..d2e35e4cc00 100644
--- a/indra/newview/skins/default/xui/en/menu_people_nearby.xml
+++ b/indra/newview/skins/default/xui/en/menu_people_nearby.xml
@@ -88,5 +88,8 @@
     name="teleport">
       <menu_item_call.on_click
        function="Avatar.OfferTeleport"/>
+      <menu_item_call.on_enable
+      function="Avatar.EnableItem"
+      parameter="can_offer_teleport"/>
     </menu_item_call>
 </context_menu>
-- 
GitLab