From 58177796fa51784da5f10298a643f972164e6d07 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Fri, 8 Oct 2010 09:34:38 +0100
Subject: Cancel chat state display when offline.

Release-Notes: Contacts will no longer show as 'typing' if you go offline before they've sent the message.

Resolves: #561

diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp
index 924ca97..9046dc3 100644
--- a/Swift/Controllers/Chat/ChatController.cpp
+++ b/Swift/Controllers/Chat/ChatController.cpp
@@ -134,6 +134,11 @@ void ChatController::setEnabled(bool enabled) {
 			chatWindow_->setAckState(it->second, ChatWindow::Failed);
 		}
 		unackedStanzas_.clear();
+
+		Presence::ref fakeOffline(new Presence());
+		fakeOffline->setFrom(toJID_);
+		fakeOffline->setType(Presence::Unavailable);
+		chatStateTracker_->handlePresenceChange(fakeOffline);
 	}
 	ChatControllerBase::setEnabled(enabled);
 }
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index 8c93120..d3bc6ce 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -151,7 +151,7 @@ void ChatsManager::setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info) {
 /**
  * This is to be called on connect/disconnect.
  */ 
-void ChatsManager::setEnabled(bool enabled) {
+void ChatsManager::setOnline(bool enabled) {
 	foreach (JIDChatControllerPair controllerPair, chatControllers_) {
 		controllerPair.second->setEnabled(enabled);
 	}
diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h
index 1e31458..326a540 100644
--- a/Swift/Controllers/Chat/ChatsManager.h
+++ b/Swift/Controllers/Chat/ChatsManager.h
@@ -41,7 +41,7 @@ namespace Swift {
 			ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, EventController* eventController, ChatWindowFactory* chatWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, boost::shared_ptr<DiscoInfo> serverDiscoInfo, PresenceSender* presenceSender, UIEventStream* uiEventStream, ChatListWindowFactory* chatListWindowFactory, bool useDelayForLatency, TimerFactory* timerFactory, MUCRegistry* mucRegistry, EntityCapsManager* entityCapsManager);
 			virtual ~ChatsManager();
 			void setAvatarManager(AvatarManager* avatarManager);
-			void setEnabled(bool enabled);
+			void setOnline(bool enabled);
 			void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info);
 			void handleIncomingMessage(boost::shared_ptr<Message> message);
 		private:
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 37dc0a9..e3079ac 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -310,7 +310,7 @@ void MainController::handleConnected() {
 
 	vcardManager_->requestOwnVCard();
 	
-	setManagersEnabled(true);
+	setManagersOnline(true);
 	//Send presence last to catch all the incoming presences.
 	sendPresence(statusTracker_->getNextPresence());
 }
@@ -521,12 +521,12 @@ void MainController::logout() {
 		rosterController_->getWindow()->setMyStatusType(StatusShow::None);
 		rosterController_->getWindow()->setMyStatusText("");
 	}
-	setManagersEnabled(false);
+	setManagersOnline(false);
 }
 
-void MainController::setManagersEnabled(bool enabled) {
+void MainController::setManagersOnline(bool enabled) {
 	if (chatsManager_) {
-		chatsManager_->setEnabled(enabled);
+		chatsManager_->setOnline(enabled);
 	}
 	if (rosterController_) {
 		rosterController_->setEnabled(enabled);
diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h
index d5a8406..163a260 100644
--- a/Swift/Controllers/MainController.h
+++ b/Swift/Controllers/MainController.h
@@ -118,7 +118,7 @@ namespace Swift {
 	
 			void performLoginFromCachedCredentials();
 			void reconnectAfterError();
-			void setManagersEnabled(bool enabled);
+			void setManagersOnline(bool enabled);
 			void handleNotificationClicked(const JID& jid);
 
 			VCardStorage* getVCardStorageForProfile(const JID& jid);
-- 
cgit v0.10.2-6-g49f6