From 315c6dec0647f6f985d73d2bd28070aa78f3899e Mon Sep 17 00:00:00 2001
From: Dmitry Oleshko <doleshko@productengine.com>
Date: Wed, 23 Dec 2009 17:25:49 +0200
Subject: [PATCH] fixed normal bug (EXT-2787) Outdated voice chat invitation
 never hides itself

- P2P and AVALINE invitationswill hide now if a call is not valid anymore
- GROUP and ADHOC invitations will stay on a screen

--HG--
branch : product-engine
---
 indra/newview/llimview.cpp                    | 63 ++++++++++++++++++-
 indra/newview/llimview.h                      | 22 ++++---
 .../default/xui/en/floater_incoming_call.xml  |  4 ++
 .../default/xui/en/floater_outgoing_call.xml  |  4 ++
 4 files changed, 85 insertions(+), 8 deletions(-)

diff --git a/indra/newview/llimview.cpp b/indra/newview/llimview.cpp
index 3345f7d0bf0..e2e3524f74f 100644
--- a/indra/newview/llimview.cpp
+++ b/indra/newview/llimview.cpp
@@ -1511,7 +1511,7 @@ bool LLOutgoingCallDialog::lifetimeHasExpired()
 	if (mLifetimeTimer.getStarted())
 	{
 		F32 elapsed_time = mLifetimeTimer.getElapsedTimeF32();
-		if (elapsed_time > LIFETIME) 
+		if (elapsed_time > mLifetime) 
 		{
 			return true;
 		}
@@ -1532,6 +1532,13 @@ void LLOutgoingCallDialog::show(const LLSD& key)
 	// hide all text at first
 	hideAllText();
 
+	// init notification's lifetime
+	std::istringstream ss( getString("lifetime") );
+	if (!(ss >> mLifetime))
+	{
+		mLifetime = DEFAULT_LIFETIME;
+	}
+
 	// customize text strings
 	// tell the user which voice channel they are leaving
 	if (!mPayload["old_channel_name"].asString().empty())
@@ -1641,6 +1648,43 @@ LLIncomingCallDialog::LLIncomingCallDialog(const LLSD& payload) :
 LLCallDialog(payload)
 {
 }
+void LLIncomingCallDialog::draw()
+{
+	if (lifetimeHasExpired())
+	{
+		onLifetimeExpired();
+	}
+	LLDockableFloater::draw();
+}
+
+bool LLIncomingCallDialog::lifetimeHasExpired()
+{
+	if (mLifetimeTimer.getStarted())
+	{
+		F32 elapsed_time = mLifetimeTimer.getElapsedTimeF32();
+		if (elapsed_time > mLifetime) 
+		{
+			return true;
+		}
+	}
+	return false;
+}
+
+void LLIncomingCallDialog::onLifetimeExpired()
+{
+	// check whether a call is valid or not
+	if (LLVoiceClient::getInstance()->findSession(mPayload["caller_id"].asUUID()))
+	{
+		// restart notification's timer if call is still valid
+		mLifetimeTimer.start();
+	}
+	else
+	{
+		// close invitation if call is already not valid
+		mLifetimeTimer.stop();
+		closeFloater();
+	}
+}
 
 BOOL LLIncomingCallDialog::postBuild()
 {
@@ -1650,6 +1694,13 @@ BOOL LLIncomingCallDialog::postBuild()
 	LLSD caller_id = mPayload["caller_id"];
 	std::string caller_name = mPayload["caller_name"].asString();
 	
+	// init notification's lifetime
+	std::istringstream ss( getString("lifetime") );
+	if (!(ss >> mLifetime))
+	{
+		mLifetime = DEFAULT_LIFETIME;
+	}
+
 	std::string call_type;
 	if (gAgent.isInGroup(session_id))
 	{
@@ -1687,6 +1738,16 @@ BOOL LLIncomingCallDialog::postBuild()
 	childSetAction("Start IM", onStartIM, this);
 	childSetFocus("Accept");
 
+	if(mPayload["notify_box_type"] != "VoiceInviteGroup" && mPayload["notify_box_type"] != "VoiceInviteAdHoc")
+	{
+		// starting notification's timer for P2P and AVALINE invitations
+		mLifetimeTimer.start();
+	}
+	else
+	{
+		mLifetimeTimer.stop();
+	}
+
 	return TRUE;
 }
 
diff --git a/indra/newview/llimview.h b/indra/newview/llimview.h
index 92caf0af9a5..d0ac819161e 100644
--- a/indra/newview/llimview.h
+++ b/indra/newview/llimview.h
@@ -489,6 +489,14 @@ class LLCallDialog : public LLDockableFloater
 	virtual BOOL postBuild();
 
 protected:
+	// lifetime timer for a notification
+	LLTimer	mLifetimeTimer;
+	// notification's lifetime in seconds
+	S32		mLifetime;
+	static const S32 DEFAULT_LIFETIME = 5;
+	virtual bool lifetimeHasExpired() {return false;};
+	virtual void onLifetimeExpired() {};
+
 	virtual void getAllowedRect(LLRect& rect);
 	LLSD mPayload;
 };
@@ -501,11 +509,16 @@ class LLIncomingCallDialog : public LLCallDialog
 	/*virtual*/ BOOL postBuild();
 	/*virtual*/ void onOpen(const LLSD& key);
 
+	// check timer state
+	/*virtual*/ void draw();
+
 	static void onAccept(void* user_data);
 	static void onReject(void* user_data);
 	static void onStartIM(void* user_data);
 
 private:
+	/*virtual*/ bool lifetimeHasExpired();
+	/*virtual*/ void onLifetimeExpired();
 	void processCallResponse(S32 response);
 };
 
@@ -524,15 +537,10 @@ class LLOutgoingCallDialog : public LLCallDialog
 	/*virtual*/ void draw();
 
 private:
-
 	// hide all text boxes
 	void hideAllText();
-	// lifetime timer for NO_ANSWER notification
-	LLTimer	mLifetimeTimer;
-	// lifetime duration for NO_ANSWER notification
-	static const S32 LIFETIME = 5;
-	bool lifetimeHasExpired();
-	void onLifetimeExpired();
+	/*virtual*/ bool lifetimeHasExpired();
+	/*virtual*/ void onLifetimeExpired();
 };
 
 // Globals
diff --git a/indra/newview/skins/default/xui/en/floater_incoming_call.xml b/indra/newview/skins/default/xui/en/floater_incoming_call.xml
index 81c54ae55e7..b9ce11600ff 100644
--- a/indra/newview/skins/default/xui/en/floater_incoming_call.xml
+++ b/indra/newview/skins/default/xui/en/floater_incoming_call.xml
@@ -10,6 +10,10 @@
  help_topic="incoming_call"
  title="UNKNOWN PERSON IS CALLING"
  width="410">
+    <floater.string
+     name="lifetime">
+        5
+    </floater.string>
     <floater.string
      name="localchat">
         Nearby Voice Chat
diff --git a/indra/newview/skins/default/xui/en/floater_outgoing_call.xml b/indra/newview/skins/default/xui/en/floater_outgoing_call.xml
index c6bc093c6c9..104ac2143f9 100644
--- a/indra/newview/skins/default/xui/en/floater_outgoing_call.xml
+++ b/indra/newview/skins/default/xui/en/floater_outgoing_call.xml
@@ -10,6 +10,10 @@
  help_topic="outgoing_call"
  title="CALLING"
  width="410">
+    <floater.string
+     name="lifetime">
+        5
+    </floater.string>
     <floater.string
      name="localchat">
         Nearby Voice Chat
-- 
GitLab