diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/RosterController.cpp | 13 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/RosterControllerTest.cpp | 63 |
2 files changed, 71 insertions, 5 deletions
diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp index 9e50f0e..dfe34b0 100644 --- a/Swift/Controllers/RosterController.cpp +++ b/Swift/Controllers/RosterController.cpp @@ -236,12 +236,15 @@ void RosterController::handleIncomingPresence(Presence::ref newPresence) { return; } Presence::ref appliedPresence(newPresence); - if (newPresence->getType() == Presence::Unsubscribe) { - /* In 3921bis, subscription removal isn't followed by a presence push of unavailable*/ - appliedPresence = boost::shared_ptr<Presence>(new Presence()); - appliedPresence->setFrom(newPresence->getFrom().toBare()); + JID newJID(appliedPresence->getFrom()); + Presence::ref highestPresence = presenceOracle_->getHighestPriorityPresence(appliedPresence->getFrom().toBare()); + JID highestJID(highestPresence->getFrom()); + bool highestPriority = (newJID == highestJID || highestPresence->getType() == Presence::Unavailable); + if (!highestPriority) { + /* Update in case there are full-JID roster entries.*/ + roster_->applyOnItems(SetPresence(appliedPresence, JID::WithResource)); } - roster_->applyOnItems(SetPresence(appliedPresence)); + roster_->applyOnItems(SetPresence(highestPresence)); } void RosterController::handleSubscriptionRequest(const JID& jid, const String& message) { diff --git a/Swift/Controllers/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/UnitTest/RosterControllerTest.cpp index 92336f6..e4770d7 100644 --- a/Swift/Controllers/UnitTest/RosterControllerTest.cpp +++ b/Swift/Controllers/UnitTest/RosterControllerTest.cpp @@ -43,6 +43,9 @@ class RosterControllerTest : public CppUnit::TestFixture CPPUNIT_TEST(testReceiveRename); CPPUNIT_TEST(testSendRename); CPPUNIT_TEST(testSendRegroup); + CPPUNIT_TEST(testPresence); + CPPUNIT_TEST(testHighestPresence); + CPPUNIT_TEST(testNotHighestPresence); CPPUNIT_TEST_SUITE_END(); public: @@ -88,6 +91,66 @@ class RosterControllerTest : public CppUnit::TestFixture return dynamic_cast<GroupRosterItem*>(CHILDREN[i]); } + JID withResource(const JID& jid, const String& resource) { + return JID(jid.toBare().toString() + "/" + resource); + } + + void testPresence() { + std::vector<String> groups; + groups.push_back("testGroup1"); + groups.push_back("testGroup2"); + JID from("test@testdomain.com"); + xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both); + Presence::ref presence(new Presence()); + presence->setFrom(withResource(from, "bob")); + presence->setPriority(2); + presence->setStatus("So totally here"); + stanzaChannel_->onPresenceReceived(presence); + ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]); + CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item->getStatusText()); + ContactRosterItem* item2 = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[1])->getChildren()[0]); + CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item2->getStatusText()); + + }; + + void testHighestPresence() { + std::vector<String> groups; + groups.push_back("testGroup1"); + JID from("test@testdomain.com"); + xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both); + Presence::ref lowPresence(new Presence()); + lowPresence->setFrom(withResource(from, "bob")); + lowPresence->setPriority(2); + lowPresence->setStatus("Not here"); + Presence::ref highPresence(new Presence()); + highPresence->setFrom(withResource(from, "bert")); + highPresence->setPriority(10); + highPresence->setStatus("So totally here"); + stanzaChannel_->onPresenceReceived(lowPresence); + stanzaChannel_->onPresenceReceived(highPresence); + ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]); + CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText()); + }; + + void testNotHighestPresence() { + std::vector<String> groups; + groups.push_back("testGroup1"); + JID from("test@testdomain.com"); + xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both); + Presence::ref lowPresence(new Presence()); + lowPresence->setFrom(withResource(from, "bob")); + lowPresence->setPriority(2); + lowPresence->setStatus("Not here"); + Presence::ref highPresence(new Presence()); + highPresence->setFrom(withResource(from, "bert")); + highPresence->setPriority(10); + highPresence->setStatus("So totally here"); + stanzaChannel_->onPresenceReceived(highPresence); + stanzaChannel_->onPresenceReceived(lowPresence); + ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]); + CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText()); + }; + void testAdd() { std::vector<String> groups; groups.push_back("testGroup1"); |