From 40949724345a00a22b1fae5d0645c244cbf47567 Mon Sep 17 00:00:00 2001
From: maxim_productengine <mnikolenko@productengine.com>
Date: Wed, 14 Nov 2012 15:28:05 +0200
Subject: [PATCH] CHUI-389 FIXED Added parameter for sessionAdded to get access
 to has_offline_msg value. Set UnreadIMs icon to visible if messages were sent
 while offline.

---
 indra/newview/llchiclet.h                   |  2 +-
 indra/newview/llchicletbar.cpp              |  2 +-
 indra/newview/llchicletbar.h                |  2 +-
 indra/newview/llconversationlog.cpp         | 33 ++++++++++++++++-----
 indra/newview/llconversationlog.h           | 12 ++++----
 indra/newview/llconversationloglist.cpp     |  4 +++
 indra/newview/llconversationloglistitem.cpp |  5 ++++
 indra/newview/llconversationloglistitem.h   |  1 +
 indra/newview/llfloaterimcontainer.cpp      |  2 +-
 indra/newview/llfloaterimcontainer.h        |  2 +-
 indra/newview/llimview.cpp                  |  6 ++--
 indra/newview/llimview.h                    |  4 +--
 indra/newview/llsyswellwindow.cpp           |  2 +-
 indra/newview/llsyswellwindow.h             |  2 +-
 14 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/indra/newview/llchiclet.h b/indra/newview/llchiclet.h
index 3c8389e20d4..d6be2df1035 100644
--- a/indra/newview/llchiclet.h
+++ b/indra/newview/llchiclet.h
@@ -873,7 +873,7 @@ class LLIMWellChiclet : public LLSysWellChiclet, LLIMSessionObserver
 {
 	friend class LLUICtrlFactory;
 public:
-	/*virtual*/ void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id) {}
+	/*virtual*/ void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg) {}
     /*virtual*/ void sessionActivated(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id) {}
 	/*virtual*/ void sessionVoiceOrIMStarted(const LLUUID& session_id) {};
 	/*virtual*/ void sessionRemoved(const LLUUID& session_id) { messageCountChanged(LLSD()); }
diff --git a/indra/newview/llchicletbar.cpp b/indra/newview/llchicletbar.cpp
index ad7890b47a6..c66ae1cdd07 100644
--- a/indra/newview/llchicletbar.cpp
+++ b/indra/newview/llchicletbar.cpp
@@ -84,7 +84,7 @@ LLIMChiclet* LLChicletBar::createIMChiclet(const LLUUID& session_id)
 }
 
 //virtual
-void LLChicletBar::sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id)
+void LLChicletBar::sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg)
 {
 	if (!getChicletPanel()) return;
 
diff --git a/indra/newview/llchicletbar.h b/indra/newview/llchicletbar.h
index a9a5b61ae74..dc991ca772b 100644
--- a/indra/newview/llchicletbar.h
+++ b/indra/newview/llchicletbar.h
@@ -50,7 +50,7 @@ class LLChicletBar
 	LLChicletPanel*	getChicletPanel() { return mChicletPanel; }
 
 	// LLIMSessionObserver observe triggers
-	/*virtual*/ void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id);
+	/*virtual*/ void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg);
     /*virtual*/ void sessionActivated(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id) {};
 	/*virtual*/ void sessionVoiceOrIMStarted(const LLUUID& session_id) {};
 	/*virtual*/ void sessionRemoved(const LLUUID& session_id);
diff --git a/indra/newview/llconversationlog.cpp b/indra/newview/llconversationlog.cpp
index 3d2b6a5c003..a0765f5e162 100644
--- a/indra/newview/llconversationlog.cpp
+++ b/indra/newview/llconversationlog.cpp
@@ -223,13 +223,17 @@ void LLConversationLog::enableLogging(bool enable)
 	notifyObservers();
 }
 
-void LLConversationLog::logConversation(const LLUUID& session_id)
+void LLConversationLog::logConversation(const LLUUID& session_id, BOOL has_offline_msg)
 {
 	const LLIMModel::LLIMSession* session = LLIMModel::instance().findIMSession(session_id);
 	LLConversation* conversation = findConversation(session);
 
 	if (session && conversation)
 	{
+		if(has_offline_msg)
+		{
+			updateOfflineIMs(session, has_offline_msg);
+		}
 		updateConversationTimestamp(conversation);
 	}
 	else if (session && !conversation)
@@ -265,7 +269,22 @@ void LLConversationLog::updateConversationName(const LLIMModel::LLIMSession* ses
 	if (conversation)
 	{
 		conversation->setConverstionName(name);
-		notifyPrticularConversationObservers(conversation->getSessionID(), LLConversationLogObserver::CHANGED_NAME);
+		notifyParticularConversationObservers(conversation->getSessionID(), LLConversationLogObserver::CHANGED_NAME);
+	}
+}
+
+void LLConversationLog::updateOfflineIMs(const LLIMModel::LLIMSession* session, BOOL new_messages)
+{
+	if (!session)
+	{
+		return;
+	}
+
+	LLConversation* conversation = findConversation(session);
+	if (conversation)
+	{
+		conversation->setOfflineMessages(new_messages);
+		notifyParticularConversationObservers(conversation->getSessionID(), LLConversationLogObserver::CHANGED_OfflineIMs);
 	}
 }
 
@@ -274,7 +293,7 @@ void LLConversationLog::updateConversationTimestamp(LLConversation* conversation
 	if (conversation)
 	{
 		conversation->updateTimestamp();
-		notifyPrticularConversationObservers(conversation->getSessionID(), LLConversationLogObserver::CHANGED_TIME);
+		notifyParticularConversationObservers(conversation->getSessionID(), LLConversationLogObserver::CHANGED_TIME);
 	}
 }
 
@@ -337,9 +356,9 @@ void LLConversationLog::removeObserver(LLConversationLogObserver* observer)
 	mObservers.erase(observer);
 }
 
-void LLConversationLog::sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id)
+void LLConversationLog::sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg)
 {
-	logConversation(session_id);
+	logConversation(session_id, has_offline_msg);
 }
 
 void LLConversationLog::cache()
@@ -477,7 +496,7 @@ void LLConversationLog::notifyObservers()
 	}
 }
 
-void LLConversationLog::notifyPrticularConversationObservers(const LLUUID& session_id, U32 mask)
+void LLConversationLog::notifyParticularConversationObservers(const LLUUID& session_id, U32 mask)
 {
 	std::set<LLConversationLogObserver*>::const_iterator iter = mObservers.begin();
 	for (; iter != mObservers.end(); ++iter)
@@ -489,7 +508,7 @@ void LLConversationLog::notifyPrticularConversationObservers(const LLUUID& sessi
 void LLConversationLog::onNewMessageReceived(const LLSD& data)
 {
 	const LLUUID session_id = data["session_id"].asUUID();
-	logConversation(session_id);
+	logConversation(session_id, false);
 }
 
 void LLConversationLog::onAvatarNameCache(const LLUUID& participant_id, const LLAvatarName& av_name, const LLIMModel::LLIMSession* session)
diff --git a/indra/newview/llconversationlog.h b/indra/newview/llconversationlog.h
index 7d0b9113c6b..8f6ac3f5d1a 100644
--- a/indra/newview/llconversationlog.h
+++ b/indra/newview/llconversationlog.h
@@ -59,7 +59,7 @@ class LLConversation
 	bool				hasOfflineMessages()	const	{ return mHasOfflineIMs; }
 
 	void setConverstionName(std::string conv_name) { mConversationName = conv_name; }
-
+	void setOfflineMessages(bool new_messages) { mHasOfflineIMs = new_messages; }
 	bool isOlderThan(U32 days) const;
 
 	/*
@@ -123,7 +123,7 @@ class LLConversationLog : public LLSingleton<LLConversationLog>, LLIMSessionObse
 	void removeObserver(LLConversationLogObserver* observer);
 
 	// LLIMSessionObserver triggers
-	virtual void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id);
+	virtual void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg);
     virtual void sessionActivated(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id) {}; // Stub
 	virtual void sessionRemoved(const LLUUID& session_id){}											// Stub
 	virtual void sessionVoiceOrIMStarted(const LLUUID& session_id){};								// Stub
@@ -147,9 +147,9 @@ class LLConversationLog : public LLSingleton<LLConversationLog>, LLIMSessionObse
 	/**
 	 * adds conversation to the conversation list and notifies observers
 	 */
-	void logConversation(const LLUUID& session_id);
+	void logConversation(const LLUUID& session_id, BOOL has_offline_msg);
 
-	void notifyPrticularConversationObservers(const LLUUID& session_id, U32 mask);
+	void notifyParticularConversationObservers(const LLUUID& session_id, U32 mask);
 
 	/**
 	 * constructs file name in which conversations log will be saved
@@ -165,6 +165,7 @@ class LLConversationLog : public LLSingleton<LLConversationLog>, LLIMSessionObse
 	void createConversation(const LLIMModel::LLIMSession* session);
 	void updateConversationTimestamp(LLConversation* conversation);
 	void updateConversationName(const LLIMModel::LLIMSession* session, const std::string& name);
+	void updateOfflineIMs(const LLIMModel::LLIMSession* session, BOOL new_messages);
 
 	LLConversation* findConversation(const LLIMModel::LLIMSession* session);
 
@@ -184,7 +185,8 @@ class LLConversationLogObserver
 	enum EConversationChange
 		{
 			CHANGED_TIME = 1, // last interaction time changed
-			CHANGED_NAME = 2  // conversation name changed
+			CHANGED_NAME = 2,  // conversation name changed
+			CHANGED_OfflineIMs = 3
 		};
 
 	virtual ~LLConversationLogObserver(){}
diff --git a/indra/newview/llconversationloglist.cpp b/indra/newview/llconversationloglist.cpp
index 429e99f7ad8..6dbcb7bef78 100644
--- a/indra/newview/llconversationloglist.cpp
+++ b/indra/newview/llconversationloglist.cpp
@@ -171,6 +171,10 @@ void LLConversationLogList::changed(const LLUUID& session_id, U32 mask)
 			mIsDirty = true;
 		}
 	}
+	else if (mask & LLConversationLogObserver::CHANGED_OfflineIMs)
+	{
+		item->updateOfflineIMs();
+	}
 }
 
 void LLConversationLogList::addNewItem(const LLConversation* conversation)
diff --git a/indra/newview/llconversationloglistitem.cpp b/indra/newview/llconversationloglistitem.cpp
index 9fad0e603e9..4e984d603b3 100644
--- a/indra/newview/llconversationloglistitem.cpp
+++ b/indra/newview/llconversationloglistitem.cpp
@@ -119,6 +119,11 @@ void LLConversationLogListItem::updateName()
 	mConversationName->setValue(mConversation->getConversationName());
 }
 
+void LLConversationLogListItem::updateOfflineIMs()
+{
+	getChild<LLIconCtrl>("unread_ims_icon")->setVisible(mConversation->hasOfflineMessages());
+}
+
 void LLConversationLogListItem::onMouseEnter(S32 x, S32 y, MASK mask)
 {
 	getChildView("hovered_icon")->setVisible(true);
diff --git a/indra/newview/llconversationloglistitem.h b/indra/newview/llconversationloglistitem.h
index 57f72db3820..ee28456bbba 100644
--- a/indra/newview/llconversationloglistitem.h
+++ b/indra/newview/llconversationloglistitem.h
@@ -69,6 +69,7 @@ class LLConversationLogListItem : public LLPanel
 	 */
 	void updateTimestamp();
 	void updateName();
+	void updateOfflineIMs();
 
 private:
 
diff --git a/indra/newview/llfloaterimcontainer.cpp b/indra/newview/llfloaterimcontainer.cpp
index 962e9f4df66..af5db13023e 100644
--- a/indra/newview/llfloaterimcontainer.cpp
+++ b/indra/newview/llfloaterimcontainer.cpp
@@ -96,7 +96,7 @@ LLFloaterIMContainer::~LLFloaterIMContainer()
 	}
 }
 
-void LLFloaterIMContainer::sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id)
+void LLFloaterIMContainer::sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg)
 {
 	addConversationListItem(session_id);
 	LLFloaterIMSessionTab::addToHost(session_id);
diff --git a/indra/newview/llfloaterimcontainer.h b/indra/newview/llfloaterimcontainer.h
index ad1f0039e9b..afc8d00174e 100644
--- a/indra/newview/llfloaterimcontainer.h
+++ b/indra/newview/llfloaterimcontainer.h
@@ -85,7 +85,7 @@ class LLFloaterIMContainer
 	static void idle(void* user_data);
 
 	// LLIMSessionObserver observe triggers
-	/*virtual*/ void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id);
+	/*virtual*/ void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg);
     /*virtual*/ void sessionActivated(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id);
 	/*virtual*/ void sessionVoiceOrIMStarted(const LLUUID& session_id);
 	/*virtual*/ void sessionRemoved(const LLUUID& session_id);
diff --git a/indra/newview/llimview.cpp b/indra/newview/llimview.cpp
index 0f4bbd054a0..0bb370e6feb 100644
--- a/indra/newview/llimview.cpp
+++ b/indra/newview/llimview.cpp
@@ -724,7 +724,7 @@ bool LLIMModel::newSession(const LLUUID& session_id, const std::string& name, co
 	// When notifying observer, name of session is used instead of "name", because they may not be the
 	// same if it is an adhoc session (in this case name is localized in LLIMSession constructor).
 	std::string session_name = LLIMModel::getInstance()->getName(session_id);
-	LLIMMgr::getInstance()->notifyObserverSessionAdded(session_id, session_name, other_participant_id);
+	LLIMMgr::getInstance()->notifyObserverSessionAdded(session_id, session_name, other_participant_id,has_offline_msg);
 
 	return true;
 
@@ -2974,11 +2974,11 @@ void LLIMMgr::clearPendingAgentListUpdates(const LLUUID& session_id)
 	}
 }
 
-void LLIMMgr::notifyObserverSessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id)
+void LLIMMgr::notifyObserverSessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, bool has_offline_msg)
 {
 	for (session_observers_list_t::iterator it = mSessionObservers.begin(); it != mSessionObservers.end(); it++)
 	{
-		(*it)->sessionAdded(session_id, name, other_participant_id);
+		(*it)->sessionAdded(session_id, name, other_participant_id, has_offline_msg);
 	}
 }
 
diff --git a/indra/newview/llimview.h b/indra/newview/llimview.h
index 054388bc6c8..19b738069cb 100644
--- a/indra/newview/llimview.h
+++ b/indra/newview/llimview.h
@@ -295,7 +295,7 @@ class LLIMSessionObserver
 {
 public:
 	virtual ~LLIMSessionObserver() {}
-	virtual void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id) = 0;
+	virtual void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg) = 0;
     virtual void sessionActivated(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id) = 0;
 	virtual void sessionVoiceOrIMStarted(const LLUUID& session_id) = 0;
 	virtual void sessionRemoved(const LLUUID& session_id) = 0;
@@ -462,7 +462,7 @@ class LLIMMgr : public LLSingleton<LLIMMgr>
 
 	static void onInviteNameLookup(LLSD payload, const LLUUID& id, const std::string& name, bool is_group);
 
-	void notifyObserverSessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id);
+	void notifyObserverSessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, bool has_offline_msg);
     //Triggers when a session has already been added
     void notifyObserverSessionActivated(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id);
 	void notifyObserverSessionVoiceOrIMStarted(const LLUUID& session_id);
diff --git a/indra/newview/llsyswellwindow.cpp b/indra/newview/llsyswellwindow.cpp
index 18e0d9d0d2a..1b8bdf3b464 100644
--- a/indra/newview/llsyswellwindow.cpp
+++ b/indra/newview/llsyswellwindow.cpp
@@ -617,7 +617,7 @@ BOOL LLIMWellWindow::postBuild()
 
 //virtual
 void LLIMWellWindow::sessionAdded(const LLUUID& session_id,
-								   const std::string& name, const LLUUID& other_participant_id)
+								   const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg)
 {
 	LLIMModel::LLIMSession* session = LLIMModel::getInstance()->findIMSession(session_id);
 	if (!session) return;
diff --git a/indra/newview/llsyswellwindow.h b/indra/newview/llsyswellwindow.h
index 378d5e0aa27..d6480f1fc63 100644
--- a/indra/newview/llsyswellwindow.h
+++ b/indra/newview/llsyswellwindow.h
@@ -170,7 +170,7 @@ class LLIMWellWindow : public LLSysWellWindow, LLIMSessionObserver, LLInitClass<
 	/*virtual*/ BOOL postBuild();
 
 	// LLIMSessionObserver observe triggers
-	/*virtual*/ void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id);
+	/*virtual*/ void sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id, BOOL has_offline_msg);
     /*virtual*/ void sessionActivated(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id) {}
 	/*virtual*/ void sessionVoiceOrIMStarted(const LLUUID& session_id) {};
 	/*virtual*/ void sessionRemoved(const LLUUID& session_id);
-- 
GitLab