diff --git a/src/tests/usermanager.cpp b/src/tests/usermanager.cpp index dd896309..84b2e0b9 100644 --- a/src/tests/usermanager.cpp +++ b/src/tests/usermanager.cpp @@ -34,6 +34,8 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_TEST_SUITE_END(); public: + Swift::Presence::ref changedPresence; + void setUp (void) { setMeUp(); } @@ -165,11 +167,18 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_ASSERT_EQUAL(1, (int) received.size()); } + void handleUserPresenceChanged(User *user, Swift::Presence::ref presence) { + changedPresence = presence; + } + void connectTwoResources() { connectUser(); add2Buddies(); connectSecondResource(); + User *user = userManager->getUser("user@localhost"); + user->onPresenceChanged.connect(boost::bind(&UserManagerTest::handleUserPresenceChanged, this, user, _1)); + // we should get presences CPPUNIT_ASSERT_EQUAL(4, (int) received2.size()); CPPUNIT_ASSERT(dynamic_cast(getStanza(received2[2]))); @@ -179,6 +188,22 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest { CPPUNIT_ASSERT(dynamic_cast(getStanza(received2[3]))); CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::Away, dynamic_cast(getStanza(received2[3]))->getShow()); CPPUNIT_ASSERT_EQUAL(std::string("status2"), dynamic_cast(getStanza(received2[3]))->getStatus()); + + Swift::Presence::ref response = Swift::Presence::create(); + response->setTo("localhost"); + response->setFrom("user@localhost/resource"); + response->setType(Swift::Presence::Unavailable); + injectPresence(response); + + CPPUNIT_ASSERT_EQUAL(Swift::Presence::Available, changedPresence->getType()); + + Swift::Presence::ref response2 = Swift::Presence::create(); + response2->setTo("localhost"); + response2->setFrom("user@localhost/resource2"); + response2->setType(Swift::Presence::Unavailable); + injectPresence(response2); + + CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unavailable, changedPresence->getType()); } void disconnectUserBouncer() { diff --git a/src/user.cpp b/src/user.cpp index 82a45bdd..a142fefc 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -348,7 +348,6 @@ void User::handlePresence(Swift::Presence::ref presence, bool forceJoin) { m_resources = currentResourcesCount; - // Change legacy network presence if (m_readyForConnect) { Swift::Presence::ref highest = m_presenceOracle->getHighestPriorityPresence(m_jid.toBare());