From d06479865828102783fd9f49d6e07f9fc37c24c8 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sat, 23 Dec 2023 16:29:56 -0500
Subject: [PATCH] Fix nearby toasts not displaying

---
 indra/llui/llfloater.h                        |  2 +-
 indra/newview/llfloaterimnearbychat.cpp       | 24 +++++--
 indra/newview/llfloaterimnearbychat.h         |  1 +
 .../newview/llfloaterimnearbychathandler.cpp  | 72 ++++++++++---------
 indra/newview/llfloaterimsessiontab.h         |  2 +-
 5 files changed, 61 insertions(+), 40 deletions(-)

diff --git a/indra/llui/llfloater.h b/indra/llui/llfloater.h
index 6675edc4590..ec486dd6321 100644
--- a/indra/llui/llfloater.h
+++ b/indra/llui/llfloater.h
@@ -366,7 +366,7 @@ class LLFloater : public LLPanel, public LLInstanceTracker<LLFloater>
 	virtual void    setDocked(bool docked, bool pop_on_undock = true);
 
 	virtual void    setTornOff(bool torn_off) { mTornOff = torn_off; }
-	bool isTornOff() {return mTornOff;}
+	bool isTornOff() const {return mTornOff;}
 	void setOpenPositioning(LLFloaterEnums::EOpenPositioning pos) {mPositioning = pos;}
 
 
diff --git a/indra/newview/llfloaterimnearbychat.cpp b/indra/newview/llfloaterimnearbychat.cpp
index 200f2408c8a..6d2dc6d4b13 100644
--- a/indra/newview/llfloaterimnearbychat.cpp
+++ b/indra/newview/llfloaterimnearbychat.cpp
@@ -374,7 +374,7 @@ void LLFloaterIMNearbyChat::show()
 		openFloater(getKey());
 }
 
-bool LLFloaterIMNearbyChat::isChatVisible() const
+bool LLFloaterIMNearbyChat::isMessagePanelVisible() const
 {
 	bool isVisible = false;
 	LLFloaterIMContainer* im_box = LLFloaterIMContainer::getInstance();
@@ -383,9 +383,25 @@ bool LLFloaterIMNearbyChat::isChatVisible() const
 	if (im_box != NULL)
 	{
 		isVisible =
-				isChatMultiTab() && gSavedPerAccountSettings.getBOOL("NearbyChatIsNotTornOff")?
-						im_box->getVisible() && !im_box->isMinimized() :
-						getVisible() && !isMinimized();
+				isChatMultiTab() && !isTornOff() ?
+			im_box->isShown() && im_box->getSelectedSession().isNull() && !im_box->isMessagesPaneCollapsed() :
+			isShown() && isMessagePaneExpanded();
+	}
+
+	return isVisible;
+}
+
+bool LLFloaterIMNearbyChat::isChatVisible() const
+{
+	bool isVisible = false;
+	LLFloaterIMContainer* im_box = LLFloaterIMContainer::getInstance();
+	// Is the IM floater container ever null?
+	llassert(im_box != NULL);
+	if (im_box)
+	{
+		isVisible = !isTornOff() ?
+			im_box->isShown() && im_box->getSelectedSession().isNull() :
+			isShown();
 	}
 
 	return isVisible;
diff --git a/indra/newview/llfloaterimnearbychat.h b/indra/newview/llfloaterimnearbychat.h
index ba94c7fc083..969c4ec0b88 100644
--- a/indra/newview/llfloaterimnearbychat.h
+++ b/indra/newview/llfloaterimnearbychat.h
@@ -64,6 +64,7 @@ class LLFloaterIMNearbyChat final
 	void removeScreenChat();
 
 	void show();
+	bool isMessagePanelVisible() const;
 	bool isChatVisible() const;
 
 	/** @param archive true - to save a message to the chat history log */
diff --git a/indra/newview/llfloaterimnearbychathandler.cpp b/indra/newview/llfloaterimnearbychathandler.cpp
index 6753c037041..bc1b5a9910b 100644
--- a/indra/newview/llfloaterimnearbychathandler.cpp
+++ b/indra/newview/llfloaterimnearbychathandler.cpp
@@ -603,9 +603,12 @@ void LLFloaterIMNearbyChatHandler::processChat(const LLChat& chat_msg,
 			&& gSavedSettings.getBOOL("UseChatBubbles") )
 		|| mChannel.isDead()
 		|| !mChannel.get()->getShowToasts() )
-		&& nearby_chat->isMessagePaneExpanded())
-		// to prevent toasts in Do Not Disturb mode
-		return;//no need in toast if chat is visible or if bubble chat is enabled
+		|| nearby_chat->isMessagePanelVisible())
+		// <RYE>
+		// no need to toast if bubble chat is enabled or nearby chat toasts are disabled
+		// or if in Do Not Disturb mode
+		// or if conversation is visible and selected and not collapsed
+		return;
 
 	// arrange a channel on a screen
 	if(!mChannel.get()->getVisible())
@@ -644,37 +647,38 @@ void LLFloaterIMNearbyChatHandler::processChat(const LLChat& chat_msg,
 			toast_msg = chat_msg.mText;
 		}
 
-		bool chat_overlaps = false;
-		if(nearby_chat->getChatHistory())
-		{
-			LLRect chat_rect = nearby_chat->getChatHistory()->calcScreenRect();
-			for (std::list<LLView*>::const_iterator child_iter = gFloaterView->getChildList()->begin();
-				 child_iter != gFloaterView->getChildList()->end(); ++child_iter)
-			{
-				LLView *view = *child_iter;
-				const LLRect& rect = view->getRect();
-				if(view->isInVisibleChain() && (rect.overlaps(chat_rect)))
-				{
-					if(!nearby_chat->getChatHistory()->hasAncestor(view))
-					{
-						chat_overlaps = true;
-					}
-					break;
-				}
-			}
-		}
-		//Don't show nearby toast, if conversation is visible and selected
-		if ((nearby_chat->hasFocus()) ||
-			(LLFloater::isVisible(nearby_chat) && nearby_chat->isTornOff() && !nearby_chat->isMinimized()) ||
-		    ((im_box->getSelectedSession().isNull() && !chat_overlaps &&
-				((LLFloater::isVisible(im_box) && !nearby_chat->isTornOff() && !im_box->isMinimized())
-						|| (LLFloater::isVisible(nearby_chat) && nearby_chat->isTornOff() && !nearby_chat->isMinimized())))))
-		{
-			if(nearby_chat->isMessagePaneExpanded())
-			{
-				return;
-			}
-		}
+		// This is insane.
+		//bool chat_overlaps = false;
+		//if(nearby_chat->getChatHistory())
+		//{
+		//	LLRect chat_rect = nearby_chat->getChatHistory()->calcScreenRect();
+		//	for (std::list<LLView*>::const_iterator child_iter = gFloaterView->getChildList()->begin();
+		//		 child_iter != gFloaterView->getChildList()->end(); ++child_iter)
+		//	{
+		//		LLView *view = *child_iter;
+		//		const LLRect& rect = view->getRect();
+		//		if(view->isInVisibleChain() && (rect.overlaps(chat_rect)))
+		//		{
+		//			if(!nearby_chat->getChatHistory()->hasAncestor(view))
+		//			{
+		//				chat_overlaps = true;
+		//			}
+		//			break;
+		//		}
+		//	}
+		//}
+		////Don't show nearby toast, if conversation is visible and selected
+		//if ((nearby_chat->hasFocus()) ||
+		//	(LLFloater::isVisible(nearby_chat) && nearby_chat->isTornOff() && !nearby_chat->isMinimized()) ||
+		//    ((im_box->getSelectedSession().isNull() && !chat_overlaps &&
+		//		((LLFloater::isVisible(im_box) && !nearby_chat->isTornOff() && !im_box->isMinimized())
+		//				|| (LLFloater::isVisible(nearby_chat) && nearby_chat->isTornOff() && !nearby_chat->isMinimized())))))
+		//{
+		//	if(nearby_chat->isMessagePaneExpanded())
+		//	{
+		//		return;
+		//	}
+		//}
 
         //Will show toast when chat preference is set        
         if((gSavedSettings.getString("NotificationNearbyChatOptions") == "toast") || !nearby_chat->isMessagePaneExpanded())
diff --git a/indra/newview/llfloaterimsessiontab.h b/indra/newview/llfloaterimsessiontab.h
index 34f4ea6c1c1..a28f1d1087c 100644
--- a/indra/newview/llfloaterimsessiontab.h
+++ b/indra/newview/llfloaterimsessiontab.h
@@ -96,7 +96,7 @@ class LLFloaterIMSessionTab
 	LLConversationItem* getCurSelectedViewModelItem();
 	void forceReshape();
 	virtual BOOL handleKeyHere( KEY key, MASK mask );
-	bool isMessagePaneExpanded(){return mMessagePaneExpanded;}
+	bool isMessagePaneExpanded() const {return mMessagePaneExpanded;}
 	void setMessagePaneExpanded(bool expanded){mMessagePaneExpanded = expanded;}
 	void restoreFloater();
 	void saveCollapsedState();
-- 
GitLab