Libtransport: Try to leave only MUC conversations when disconnecting the user

This commit is contained in:
Jan Kaluza 2016-02-19 15:14:49 +01:00
parent bff117e4ef
commit fbfb07e8ba
2 changed files with 24 additions and 1 deletions

View file

@ -105,8 +105,12 @@ void ConversationManager::resetResources() {
void ConversationManager::removeJID(const Swift::JID &jid) {
std::vector<std::string> toRemove;
for (std::map<std::string, Conversation *>::const_iterator it = m_convs.begin(); it != m_convs.end(); it++) {
if (it->first.empty() || !it->second) {
continue;
}
(*it).second->removeJID(jid);
if (it->second->getJIDs().empty()) {
if (it->second->getJIDs().empty() && (*it).second->isMUC()) {
toRemove.push_back(it->first);
}
}

View file

@ -30,6 +30,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesOneDisconnectsBouncer);
CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesAnotherOneDisconnects);
CPPUNIT_TEST(leaveJoinedRoom);
CPPUNIT_TEST(doNotLeaveNormalChat);
CPPUNIT_TEST(joinRoomBeforeConnected);
CPPUNIT_TEST(handleDisconnected);
CPPUNIT_TEST(handleDisconnectedReconnect);
@ -420,6 +421,24 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
CPPUNIT_ASSERT(!user->getConversationManager()->getConversation("room"));
}
void doNotLeaveNormalChat() {
User *user = userManager->getUser("user@localhost");
TestingConversation *conv = new TestingConversation(user->getConversationManager(), "buddy1@test");
user->getConversationManager()->addConversation(conv);
CPPUNIT_ASSERT_EQUAL(std::string(""), room);
CPPUNIT_ASSERT_EQUAL(std::string(""), roomNickname);
CPPUNIT_ASSERT_EQUAL(std::string(""), roomPassword);
user->getConversationManager()->removeJID("user@localhost/resource");
CPPUNIT_ASSERT_EQUAL(std::string(""), room);
CPPUNIT_ASSERT_EQUAL(std::string(""), roomNickname);
CPPUNIT_ASSERT_EQUAL(std::string(""), roomPassword);
Conversation *cv = user->getConversationManager()->getConversation("buddy1@test");
CPPUNIT_ASSERT(cv);
}
void handleDisconnected() {
User *user = userManager->getUser("user@localhost");
user->handleDisconnected("Connection error", Swift::SpectrumErrorPayload::CONNECTION_ERROR_AUTHENTICATION_FAILED);