Changeset - fbfb07e8ba22
[Not reviewed]
0 2 0
Jan Kaluza - 9 years ago 2016-02-19 15:14:49
jkaluza@redhat.com
Libtransport: Try to leave only MUC conversations when disconnecting the user
2 files changed with 24 insertions and 1 deletions:
0 comments (0 inline, 0 general)
libtransport/ConversationManager.cpp
Show inline comments
 
@@ -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);
 
		}
 
	}
tests/libtransport/user.cpp
Show inline comments
 
@@ -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);
0 comments (0 inline, 0 general)