Vadim ProductEngine avatar Vadim ProductEngine committed 8ceebd3

STORM-192 FIXED Ctrl-Shift-W not to disable nearby chat toasts.

Bug reason: The fix of EXT-1419 disables showing nearby chat showing toasts at all whenever you close one.
That was done to prevent a crash when viewer is exiting, but closing a toast manually should be handled differently.

Fix: If a toast is being closed (destroyed) manually, just remove it from the toast pool
(to prevent further references to the invalid pointer), but keep on showing new toasts.
I've overriden LLFloater::onClose() to differentiate the two cases.

Comments (0)

Files changed (1)

indra/newview/llnearbychathandler.cpp

 	typedef boost::function<LLToastPanelBase* (void )> create_toast_panel_callback_t;
 	void setCreatePanelCallback(create_toast_panel_callback_t value) { m_create_toast_panel_callback_t = value;}
 
-	void onToastDestroyed	(LLToast* toast);
+	void onToastDestroyed	(LLToast* toast, bool app_quitting);
 	void onToastFade		(LLToast* toast);
 
 	void reshape			(S32 width, S32 height, BOOL called_from_parent);
 	}
 
 protected:
+	void	deactivateToast(LLToast* toast);
 	void	addToToastPool(LLToast* toast)
 	{
 		toast->setVisible(FALSE);
 	bool	mStopProcessing;
 };
 
+//-----------------------------------------------------------------------------------------------
+// LLNearbyChatToast
+//-----------------------------------------------------------------------------------------------
+
+// We're deriving from LLToast to be able to override onClose()
+// in order to handle closing nearby chat toasts properly.
+class LLNearbyChatToast : public LLToast
+{
+	LOG_CLASS(LLNearbyChatToast);
+public:
+	LLNearbyChatToast(const LLToast::Params& p, LLNearbyChatScreenChannel* nc_channelp)
+	:	LLToast(p),
+	 	mNearbyChatScreenChannelp(nc_channelp)
+	{
+	}
+
+	/*virtual*/ void onClose(bool app_quitting);
+
+private:
+	LLNearbyChatScreenChannel*	mNearbyChatScreenChannelp;
+};
+
+//-----------------------------------------------------------------------------------------------
+// LLNearbyChatScreenChannel
+//-----------------------------------------------------------------------------------------------
+
+void LLNearbyChatScreenChannel::deactivateToast(LLToast* toast)
+{
+	std::vector<LLToast*>::iterator pos = std::find(m_active_toasts.begin(), m_active_toasts.end(), toast);
+
+	if (pos == m_active_toasts.end())
+	{
+		llassert(pos == m_active_toasts.end());
+		return;
+	}
+
+	m_active_toasts.erase(pos);
+}
+
 void	LLNearbyChatScreenChannel::createOverflowToast(S32 bottom, F32 timer)
 {
 	//we don't need overflow toast in nearby chat
 }
 
-void LLNearbyChatScreenChannel::onToastDestroyed(LLToast* toast)
+void LLNearbyChatScreenChannel::onToastDestroyed(LLToast* toast, bool app_quitting)
 {	
-	mStopProcessing = true;
+	if (app_quitting)
+	{
+		// Viewer is quitting.
+		// Immediately stop processing chat messages (EXT-1419).
+		mStopProcessing = true;
+	}
+	else
+	{
+		// The toast is being closed by user (STORM-192).
+		// Remove it from the list of active toasts to prevent
+		// further references to the invalid pointer.
+		deactivateToast(toast);
+	}
 }
 
 void LLNearbyChatScreenChannel::onToastFade(LLToast* toast)
 	if(!toast)
 		return;
 
-	std::vector<LLToast*>::iterator pos = std::find(m_active_toasts.begin(),m_active_toasts.end(),toast);
-	if(pos!=m_active_toasts.end())
-		m_active_toasts.erase(pos);
+	deactivateToast(toast);
 
 	addToToastPool(toast);
 	
 	p.lifetime_secs = gSavedSettings.getS32("NearbyToastLifeTime");
 	p.fading_time_secs = gSavedSettings.getS32("NearbyToastFadingTime");
 
-	LLToast* toast = new LLToast(p); 
+	LLToast* toast = new LLNearbyChatToast(p, this);
 	
 	
 	toast->setOnFadeCallback(boost::bind(&LLNearbyChatScreenChannel::onToastFade, this, _1));
-	toast->setOnToastDestroyedCallback(boost::bind(&LLNearbyChatScreenChannel::onToastDestroyed, this, _1));
 	
 	m_toast_pool.push_back(toast);
 	return true;
 }
 
 
+//-----------------------------------------------------------------------------------------------
+// LLNearbyChatToast
+//-----------------------------------------------------------------------------------------------
 
+// virtual
+void LLNearbyChatToast::onClose(bool app_quitting)
+{
+	mNearbyChatScreenChannelp->onToastDestroyed(this, app_quitting);
+}
+
+// EOF
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.