diff --git a/indra/newview/llfloaterimnearbychat.cpp b/indra/newview/llfloaterimnearbychat.cpp
index b2a9a0e99ff1ffbb06d7de88129928d74b953a92..d543012e83519253e2bfa9f8f0e4892740cd4201 100644
--- a/indra/newview/llfloaterimnearbychat.cpp
+++ b/indra/newview/llfloaterimnearbychat.cpp
@@ -208,6 +208,35 @@ void LLFloaterIMNearbyChat::closeHostedFloater()
 	}
 }
 
+void LLFloaterIMNearbyChat::closeFloater(bool app_quitting)
+{
+	LLFloaterEmojiPicker::saveState();
+
+	// If detached from conversations window close anyway
+	if (!getHost())
+	{
+		LLFloaterIMSessionTab::closeFloater(app_quitting);
+	}
+
+	// Should check how many conversations are ongoing. Select next to "Nearby Chat" in case there are some other besides.
+	// Close conversations window in case "Nearby Chat" is attached and the only conversation
+	LLFloaterIMContainer* floater_container = LLFloaterIMContainer::getInstance();
+	if (floater_container->getConversationListItemSize() == 1)
+	{
+		if (getHost())
+		{
+			floater_container->closeFloater(app_quitting);
+		}
+	}
+	else
+	{
+		if (!getHost())
+		{
+			floater_container->selectNextConversationByID(LLUUID());
+		}
+	}
+}
+
 // virtual
 void LLFloaterIMNearbyChat::refresh()
 {
diff --git a/indra/newview/llfloaterimnearbychat.h b/indra/newview/llfloaterimnearbychat.h
index ca52b97b6776139fede7d37925856f57fcb1540c..c3db4943abf934ae9108a90cb5b8e7281fc82b50 100644
--- a/indra/newview/llfloaterimnearbychat.h
+++ b/indra/newview/llfloaterimnearbychat.h
@@ -65,6 +65,8 @@ class LLFloaterIMNearbyChat final
 	/*virtual*/ void setVisibleAndFrontmost(BOOL take_focus=TRUE, const LLSD& key = LLSD()) override;
 	/*virtual*/ void closeHostedFloater() override;
 
+	void	closeFloater(bool app_quitting = false) override;
+
 	void loadHistory();
     void reloadMessages(bool clean_messages = false);
 	void removeScreenChat();