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
 
@@ -102,14 +102,18 @@ 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);
 
		}
 
	}
 

	
 
	if (m_user->getUserSetting("stay_connected") != "1") {
 
		while(!toRemove.empty()) {
tests/libtransport/user.cpp
Show inline comments
 
@@ -27,12 +27,13 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesOneDisconnects);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomBouncer);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesBouncer);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesOneDisconnectsBouncer);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesAnotherOneDisconnects);
 
	CPPUNIT_TEST(leaveJoinedRoom);
 
	CPPUNIT_TEST(doNotLeaveNormalChat);
 
	CPPUNIT_TEST(joinRoomBeforeConnected);
 
	CPPUNIT_TEST(handleDisconnected);
 
	CPPUNIT_TEST(handleDisconnectedReconnect);
 
	CPPUNIT_TEST(joinRoomHandleDisconnectedRejoin);
 
	CPPUNIT_TEST(joinRoomAfterFlagNotAuthorized);
 
	CPPUNIT_TEST(requestVCard);
 
@@ -417,12 +418,30 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		received.clear();
 
		handlePresenceLeaveRoom();
 

	
 
		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);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT(streamEnded);
0 comments (0 inline, 0 general)