From 672f91a63093540d7f6aeef4dcbd69ed8accb9b9 2012-08-16 13:18:40 From: Jan Kaluza Date: 2012-08-16 13:18:40 Subject: [PATCH] Move Conversatino deletion into User class --- diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index 5bfbacf0cf2d7c1cb9381369e5e4fba093e13bce..214bf7d70eaa147cd67d4e759f93a376d58405df 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -1181,15 +1181,6 @@ void NetworkPluginServer::handleRoomLeft(User *user, const std::string &r) { return; } send(c->connection, message); - - NetworkConversation *conv = (NetworkConversation *) user->getConversationManager()->getConversation(r); - if (!conv) { - return; - } - - user->getConversationManager()->removeConversation(conv); - - delete conv; } void NetworkPluginServer::handleUserDestroyed(User *user) { diff --git a/src/tests/user.cpp b/src/tests/user.cpp index e5df9ee212d45beaea2f41e81ef296dcbf37c794..f1f03a44ea7019f3e02a56ba6063021b9ea60966 100644 --- a/src/tests/user.cpp +++ b/src/tests/user.cpp @@ -26,6 +26,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_TEST(handlePresence); CPPUNIT_TEST(handlePresenceJoinRoom); CPPUNIT_TEST(handlePresenceLeaveRoom); + CPPUNIT_TEST(leaveJoinedRoom); CPPUNIT_TEST(handleDisconnected); CPPUNIT_TEST_SUITE_END(); @@ -191,6 +192,18 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_ASSERT_EQUAL(std::string(""), roomPassword); } + void leaveJoinedRoom() { + User *user = userManager->getUser("user@localhost"); + handlePresenceJoinRoom(); + + CPPUNIT_ASSERT(user->getConversationManager()->getConversation("#room")); + + received.clear(); + handlePresenceLeaveRoom(); + + CPPUNIT_ASSERT(!user->getConversationManager()->getConversation("#room")); + } + void handleDisconnected() { User *user = userManager->getUser("user@localhost"); user->handleDisconnected("Connection error", Swift::SpectrumErrorPayload::CONNECTION_ERROR_AUTHENTICATION_FAILED); diff --git a/src/user.cpp b/src/user.cpp index d95ad8a90d5757753d85824efc7e81fd5de6064f..fff621103c1eaf7ed4b94e6881ef1496556209fa 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -217,6 +217,12 @@ void User::handlePresence(Swift::Presence::ref presence) { std::string room = Buddy::JIDToLegacyName(presence->getTo()); LOG4CXX_INFO(logger, m_jid.toString() << ": Going to left room " << room); onRoomLeft(room); + + Conversation *conv = m_conversationManager->getConversation(room); + if (conv) { + m_conversationManager->removeConversation(conv); + delete conv; + } } else { // force connection to legacy network to let backend to handle auto-join on connect.