Changeset - 3bfd7407b989
[Not reviewed]
0 5 0
Jan Kaluza - 10 years ago 2016-02-19 10:24:13
jkaluza@redhat.com
Libtransport: Send unavailable presence as a response to presence for exiting the room. Fixes room rejoin in Pidgin.
5 files changed with 26 insertions and 8 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -1312,24 +1312,26 @@ static void conv_chat_remove_users(PurpleConversation *conv, GList *users) {
 
static gboolean conv_has_focus(PurpleConversation *conv) {
 
	return TRUE;
 
}
 

	
 
static void conv_chat_topic_changed(PurpleConversation *conv, const char *who, const char *topic) {
 
	LOG4CXX_INFO(logger, "Conversation topic changed");
 
	PurpleAccount *account = purple_conversation_get_account_wrapped(conv);
 
	np->handleSubject(np->m_accounts[account], purple_conversation_get_name_wrapped(conv), topic ? topic : "", who ? who : "Spectrum 2");
 
}
 

	
 
static void conv_present(PurpleConversation *conv) {
 
	if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_CHAT) {
 
		LOG4CXX_INFO(logger, "Conversation presented");
 
		conv_chat_add_users(conv, PURPLE_CONV_CHAT_WRAPPED(conv)->in_room, TRUE);
 
		const char *topic = purple_conv_chat_get_topic(PURPLE_CONV_CHAT_WRAPPED(conv));
 
		if (topic && *topic != '\0') {
 
			conv_chat_topic_changed(conv, topic, PURPLE_CONV_CHAT_WRAPPED(conv)->who);
 
		}
 
		else {
 
			LOG4CXX_INFO(logger, "Conversation created with an empty topic");
 
		}
 
	}
 
}
 

	
 
static PurpleConversationUiOps conversation_ui_ops =
 
{
libtransport/Conversation.cpp
Show inline comments
 
@@ -387,24 +387,29 @@ void Conversation::setNickname(const std::string &nickname) {
 
		m_nicknameChanged = true;
 
	}
 
	m_nickname = nickname;
 
}
 

	
 
void Conversation::handleRawPresence(Swift::Presence::ref presence) {
 
	// TODO: Detect nickname change.
 
	m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
 
	m_participants[presence->getFrom().getResource()].presence = presence;
 
}
 

	
 
void Conversation::removeJID(const Swift::JID &jid) {
 
	if (m_muc) {
 
		Swift::Presence::ref presence = generatePresence(m_nickname, 0, Swift::StatusShow::None, "");
 
		presence->setTo(jid);
 
		m_conversationManager->getComponent()->getFrontend()->sendPresence(presence);
 
	}
 
	m_jids.remove(jid);
 
}
 

	
 
void Conversation::handleParticipantChanged(const std::string &nick, Conversation::ParticipantFlag flag, int status, const std::string &statusMessage, const std::string &newname, const std::string &iconhash, const std::string &alias) {
 
	Swift::Presence::ref presence = generatePresence(alias.empty() ? nick : alias, flag, status, statusMessage, newname, iconhash);
 

	
 
	if (presence->getType() == Swift::Presence::Unavailable) {
 
		m_participants.erase(nick);
 
	}
 
	else {
 
		m_participants[nick].presence = presence;
 
		m_participants[nick].alias = alias;
tests/libtransport/basictest.cpp
Show inline comments
 
@@ -236,24 +236,31 @@ void BasicTest::disconnectUser() {
 
	if (user) {
 
		user->addUserSetting("stay_connected", "0");
 
	}
 
	else {
 
		return;
 
	}
 
	received.clear();
 
	userManager->disconnectUser("user@localhost");
 
	dynamic_cast<Swift::DummyTimerFactory *>(factories->getTimerFactory())->setTime(100);
 
	loop->processEvents();
 

	
 
	CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 

	
 
	// When user has been in a room, unavailable presence can be sent from that room.
 
	if (received.size() == 2) {
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[1])));
 
		return;
 
	}
 
	CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
	CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
}
 

	
 
void BasicTest::add2Buddies() {
 
	User *user = userManager->getUser("user@localhost");
 
	CPPUNIT_ASSERT(user);
 

	
 
	std::vector<std::string> grp;
 
	grp.push_back("group1");
 
	LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "BuddY1", "Buddy 1", grp, BUDDY_JID_ESCAPING);
 
	user->getRosterManager()->setBuddy(buddy);
tests/libtransport/conversationmanager.cpp
Show inline comments
 
@@ -389,25 +389,27 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		// reset resources should not touch this resource
 
		user->getConversationManager()->resetResources();
 

	
 
		boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
		msg->setBody("hi there!");
 
		conv->handleMessage(msg, "anotheruser");
 

	
 
		boost::shared_ptr<Swift::Message> msg2(new Swift::Message());
 
		msg2->setBody("hi there2!");
 
		conv->handleMessage(msg2, "anotheruser");
 

	
 
		loop->processEvents();
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		// Presence from the room when disconnecting the user
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		received.clear();
 

	
 
		userRegistry->isValidUserPassword(Swift::JID("user@localhost/resource"), serverFromClientSession.get(), Swift::createSafeByteArray("password"));
 
		userRegistry->onPasswordValid(Swift::JID("user@localhost/resource"));
 
		loop->processEvents();
 

	
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("#room@localhost/hanzz");
 
		response->setFrom("user@localhost/resource");
 

	
 
		Swift::MUCPayload *payload = new Swift::MUCPayload();
 
		payload->setPassword("password");
 
		response->addPayload(boost::shared_ptr<Swift::Payload>(payload));
 
@@ -466,25 +468,27 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		// reset resources should not touch this resource
 
		user->getConversationManager()->resetResources();
 

	
 
		boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
		msg->setBody("hi there!");
 
		conv->handleMessage(msg, "anotheruser");
 

	
 
		boost::shared_ptr<Swift::Message> msg2(new Swift::Message());
 
		msg2->setBody("hi there2!");
 
		conv->handleMessage(msg2, "anotheruser");
 

	
 
		loop->processEvents();
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		// Presence to ack the user leave
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		received.clear();
 

	
 
		userRegistry->isValidUserPassword(Swift::JID("user@localhost/resource"), serverFromClientSession.get(), Swift::createSafeByteArray("password"));
 
		userRegistry->onPasswordValid(Swift::JID("user@localhost/resource"));
 
		loop->processEvents();
 

	
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("#room@localhost/hanzz");
 
		response->setFrom("user@localhost/resource");
 

	
 
		Swift::MUCPayload *payload = new Swift::MUCPayload();
 
		payload->setPassword("password");
 
		response->addPayload(boost::shared_ptr<Swift::Payload>(payload));
tests/libtransport/user.cpp
Show inline comments
 
@@ -13,25 +13,25 @@
 
using namespace Transport;
 

	
 
#if !HAVE_SWIFTEN_3
 
#define get_value_or(X) substr()
 
#endif
 

	
 
class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(UserTest);
 
	CPPUNIT_TEST(sendCurrentPresence);
 
    CPPUNIT_TEST(handlePresence);
 
	CPPUNIT_TEST(handlePresenceJoinRoom);
 
	CPPUNIT_TEST(handlePresenceJoinRoomTwoResources);
 
	CPPUNIT_TEST(handlePresenceLeaveRoom);
 
// 	CPPUNIT_TEST(handlePresenceLeaveRoom); // tested as part of other tests
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResources);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesOneDisconnects);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomBouncer);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesBouncer);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesOneDisconnectsBouncer);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesAnotherOneDisconnects);
 
	CPPUNIT_TEST(leaveJoinedRoom);
 
	CPPUNIT_TEST(joinRoomBeforeConnected);
 
	CPPUNIT_TEST(handleDisconnected);
 
	CPPUNIT_TEST(handleDisconnectedReconnect);
 
	CPPUNIT_TEST(joinRoomHandleDisconnectedRejoin);
 
	CPPUNIT_TEST(joinRoomAfterFlagNotAuthorized);
 
@@ -207,67 +207,67 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		received.clear();
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("room@localhost/hanzz");
 
		response->setFrom("user@localhost/resource");
 
		response->setType(Swift::Presence::Unavailable);
 

	
 
		Swift::MUCPayload *payload = new Swift::MUCPayload();
 
		payload->setPassword("password");
 
		response->addPayload(boost::shared_ptr<Swift::Payload>(payload));
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 

	
 
// 		CPPUNIT_ASSERT_EQUAL(std::string("room"), room);
 
// 		CPPUNIT_ASSERT_EQUAL(std::string(""), roomNickname);
 
// 		CPPUNIT_ASSERT_EQUAL(std::string(""), roomPassword);
 
	}
 

	
 
	void handlePresenceLeaveRoomTwoResources() {
 
		handlePresenceJoinRoomTwoResources();
 
		received.clear();
 

	
 
		// User is still connected from resource2, so he should not leave the room
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("room@localhost/hanzz");
 
		response->setFrom("user@localhost/resource");
 
		response->setType(Swift::Presence::Unavailable);
 

	
 
		Swift::MUCPayload *payload = new Swift::MUCPayload();
 
		payload->setPassword("password");
 
		response->addPayload(boost::shared_ptr<Swift::Payload>(payload));
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 

	
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), room);
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), roomNickname);
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), roomPassword);
 

	
 
		// disconnect also from resource
 
		// User is still connected from resource2, so he should not leave the room
 
		response = Swift::Presence::create();
 
		response->setTo("room@localhost/hanzz");
 
		response->setFrom("user@localhost/resource2");
 
		response->setType(Swift::Presence::Unavailable);
 

	
 
		payload = new Swift::MUCPayload();
 
		payload->setPassword("password");
 
		response->addPayload(boost::shared_ptr<Swift::Payload>(payload));
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 

	
 
		CPPUNIT_ASSERT_EQUAL(std::string("room"), room);
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), roomNickname);
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), roomPassword);
 
	}
 

	
 
	void handlePresenceLeaveRoomTwoResourcesOneDisconnects() {
 
		handlePresenceJoinRoomTwoResources();
 
		received.clear();
 
		User *user = userManager->getUser("user@localhost");
 

	
 
		// User is still connected from resource2, so he should not leave the room
 
@@ -348,45 +348,45 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		// User is still connected from resource2, so he should not leave the room
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("room@localhost/hanzz");
 
		response->setFrom("user@localhost/resource");
 
		response->setType(Swift::Presence::Unavailable);
 

	
 
		Swift::MUCPayload *payload = new Swift::MUCPayload();
 
		payload->setPassword("password");
 
		response->addPayload(boost::shared_ptr<Swift::Payload>(payload));
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 

	
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), room);
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), roomNickname);
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), roomPassword);
 

	
 
		room = "something";
 
		// disconnect also from resource
 
		// User is still connected from resource2, so he should not leave the room
 
		response = Swift::Presence::create();
 
		response->setTo("room@localhost/hanzz");
 
		response->setFrom("user@localhost/resource2");
 
		response->setType(Swift::Presence::Unavailable);
 

	
 
		payload = new Swift::MUCPayload();
 
		payload->setPassword("password");
 
		response->addPayload(boost::shared_ptr<Swift::Payload>(payload));
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 

	
 
		CPPUNIT_ASSERT_EQUAL(std::string("something"), room);
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), roomNickname);
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), roomPassword);
 
	}
 

	
 
	void handlePresenceLeaveRoomTwoResourcesOneDisconnectsBouncer() {
 
		room = "something";
 
		handlePresenceJoinRoomTwoResources();
 
		received.clear();
 
		User *user = userManager->getUser("user@localhost");
 

	
0 comments (0 inline, 0 general)