From 5caf2316dad81d6c02ff3e886a65121011ccc9fe Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 28 Nov 2010 11:37:47 +0000 Subject: Rebind chat dialogs on just about anything. Resolves: #646 Release-Notes: Duplicate chat windows when contacts are using multiple clients should now be avoided. diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index 2fc5a43..6bd7597 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -133,7 +133,7 @@ void ChatsManager::handleUIEvent(boost::shared_ptr event) { */ void ChatsManager::handlePresenceChange(boost::shared_ptr newPresence) { if (mucRegistry_->isMUC(newPresence->getFrom().toBare())) return; - if (newPresence->getType() != Presence::Unavailable) return; + //if (newPresence->getType() != Presence::Unavailable) return; JID fullJID(newPresence->getFrom()); std::map::iterator it = chatControllers_.find(fullJID); if (it == chatControllers_.end()) return; @@ -218,6 +218,12 @@ ChatController* ChatsManager::getChatControllerIfExists(const JID &contact) { if (chatControllers_.find(bare) != chatControllers_.end()) { rebindControllerJID(bare, contact); } else { + foreach (JIDChatControllerPair pair, chatControllers_) { + if (pair.first.toBare() == contact.toBare()) { + rebindControllerJID(pair.first, contact); + return chatControllers_[contact]; + } + } return NULL; } } diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp index 08106e6..c180062 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp @@ -136,15 +136,15 @@ public: JID messageJID2("testling@test.com/resource2"); - MockChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock(); - mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID2, uiEventStream_).Return(window2); + //MockChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock(); + //mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID2, uiEventStream_).Return(window2); boost::shared_ptr message2(new Message()); message2->setFrom(messageJID2); String body2("This is a legible message. .cmaulm.chul"); message2->setBody(body2); manager_->handleIncomingMessage(message2); - CPPUNIT_ASSERT_EQUAL(body2, window2->lastMessageBody_); + CPPUNIT_ASSERT_EQUAL(body2, window1->lastMessageBody_); } void testFirstOpenWindowOutgoing() { @@ -239,14 +239,14 @@ public: uiEventStream_->send(boost::shared_ptr(new RequestChatUIEvent(JID(messageJIDString1)))); String messageJIDString2("testling@test.com/2"); - ChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock(); - mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString2), uiEventStream_).Return(window2); + //ChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock(); + //mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString2), uiEventStream_).Return(window2); uiEventStream_->send(boost::shared_ptr(new RequestChatUIEvent(JID(messageJIDString2)))); String messageJIDString3("testling@test.com/3"); - ChatWindow* window3 = new MockChatWindow();//mocks_->InterfaceMock(); - mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString3), uiEventStream_).Return(window3); + //ChatWindow* window3 = new MockChatWindow();//mocks_->InterfaceMock(); + //mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(JID(messageJIDString3), uiEventStream_).Return(window3); uiEventStream_->send(boost::shared_ptr(new RequestChatUIEvent(JID(messageJIDString3)))); @@ -278,8 +278,8 @@ public: JID messageJID2("testling@test.com/resource2"); - MockChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock(); - mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID2, uiEventStream_).Return(window2); + //MockChatWindow* window2 = new MockChatWindow();//mocks_->InterfaceMock(); + //mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID2, uiEventStream_).Return(window2); boost::shared_ptr message2(new Message()); message2->setFrom(messageJID2); @@ -314,7 +314,7 @@ public: String body2b("This is a legible message2b."); message2b->setBody(body2b); manager_->handleIncomingMessage(message2b); - CPPUNIT_ASSERT_EQUAL(body2b, window2->lastMessageBody_); + CPPUNIT_ASSERT_EQUAL(body2b, window1->lastMessageBody_); } private: -- cgit v0.10.2-6-g49f6