Libtransport: Send unavailable presence as a response to presence for exiting the room. Fixes room rejoin in Pidgin.

This commit is contained in:
Jan Kaluza 2016-02-19 10:24:13 +01:00
parent 9391c487b5
commit 3bfd7407b9
5 changed files with 26 additions and 8 deletions

View file

@ -1321,6 +1321,8 @@ static void conv_chat_topic_changed(PurpleConversation *conv, const char *who, c
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);

View file

@ -396,6 +396,11 @@ void Conversation::handleRawPresence(Swift::Presence::ref 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);
}

View file

@ -245,6 +245,13 @@ void BasicTest::disconnectUser() {
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])));
}

View file

@ -398,7 +398,9 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
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"));
@ -475,7 +477,9 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
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"));

View file

@ -22,7 +22,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
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);
@ -216,7 +216,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
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);
@ -239,7 +239,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
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);
@ -258,7 +258,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
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);
@ -357,7 +357,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
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);
@ -377,7 +377,7 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
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);