From a0199d151c8c0286caa5185988b5604d7e1e2d52 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Fri, 16 Sep 2016 11:47:40 +0200 Subject: Fix presence handling of own contact in roster Previously, presence from your own full JID was not applied to your own roster entry. With this commit all presence changes are applied. Test-Information: Added unit test verifying new behavior. All unit tests pass on OS X 10.11.6. Change-Id: Ib93f487329aa1eec0e876857541780ff44b8cac9 diff --git a/Swift/Controllers/Roster/RosterController.cpp b/Swift/Controllers/Roster/RosterController.cpp index 1c750a3..116ef2e 100644 --- a/Swift/Controllers/Roster/RosterController.cpp +++ b/Swift/Controllers/Roster/RosterController.cpp @@ -384,9 +384,7 @@ void RosterController::handlePresenceChanged(Presence::ref presence) { ownContact_->applyPresence(presence); mainWindow_->setMyContactRosterItem(ownContact_); } - else { - handleIncomingPresence(presence); - } + handleIncomingPresence(presence); } boost::optional RosterController::getItem(const JID& jid) const { diff --git a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp index e01f78a..0cd4080 100644 --- a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp +++ b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -61,6 +60,7 @@ class RosterControllerTest : public CppUnit::TestFixture { CPPUNIT_TEST(testNotHighestPresence); CPPUNIT_TEST(testUnavailablePresence); CPPUNIT_TEST(testRemoveResultsInUnavailablePresence); + CPPUNIT_TEST(testOwnContactInRosterPresence); CPPUNIT_TEST_SUITE_END(); public: @@ -146,7 +146,6 @@ class RosterControllerTest : public CppUnit::TestFixture { ContactRosterItem* item2 = dynamic_cast(dynamic_cast(CHILDREN[1])->getChildren()[0]); CPPUNIT_ASSERT(item2); CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item2->getStatusText()); - } void testHighestPresence() { @@ -354,8 +353,27 @@ class RosterControllerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presenceOracle_->getAllPresence("test@testdomain.com")[0]->getType()); } + void testOwnContactInRosterPresence() { + std::vector groups; + groups.push_back("testGroup1"); + groups.push_back("testGroup2"); + JID from = jid_; + xmppRoster_->addContact(from.toBare(), "name", groups, RosterItemPayload::Both); + Presence::ref presence(new Presence()); + presence->setFrom(from); + presence->setPriority(2); + presence->setStatus("So totally here"); + stanzaChannel_->onPresenceReceived(presence); + ContactRosterItem* item = dynamic_cast(dynamic_cast(CHILDREN[0])->getChildren()[0]); + CPPUNIT_ASSERT(item); + CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item->getStatusText()); + ContactRosterItem* item2 = dynamic_cast(dynamic_cast(CHILDREN[1])->getChildren()[0]); + CPPUNIT_ASSERT(item2); + CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item2->getStatusText()); + } + void assertVectorsEqual(const std::vector& v1, const std::vector& v2, int line) { - foreach (const std::string& entry, v1) { + for (const auto& entry : v1) { if (std::find(v2.begin(), v2.end(), entry) == v2.end()) { std::stringstream stream; stream << "Couldn't find " << entry << " in v2 (line " << line << ")"; -- cgit v0.10.2-6-g49f6