Ejemplo n.º 1
0
	void testUnavailablePresence() {
		std::vector<std::string> groups;
		groups.push_back("testGroup1");
		JID from("*****@*****.**");
		xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);

		Presence::ref lowPresence(new Presence());
		lowPresence->setFrom(withResource(from, "bob"));
		lowPresence->setPriority(2);
		lowPresence->setShow(StatusShow::Away);
		lowPresence->setStatus("Not here");
		Presence::ref lowPresenceOffline(new Presence());
		lowPresenceOffline->setFrom(withResource(from, "bob"));
		lowPresenceOffline->setStatus("Signing out");
		lowPresenceOffline->setType(Presence::Unavailable);

		Presence::ref highPresence(new Presence());
		highPresence->setFrom(withResource(from, "bert"));
		highPresence->setPriority(10);
		highPresence->setStatus("So totally here");
		Presence::ref highPresenceOffline(new Presence());
		highPresenceOffline->setFrom(withResource(from, "bert"));
		highPresenceOffline->setType(Presence::Unavailable);

		stanzaChannel_->onPresenceReceived(lowPresence);
		Presence::ref accountPresence = presenceOracle_->getAccountPresence(from);
		CPPUNIT_ASSERT_EQUAL(StatusShow::Away, accountPresence->getShow());

		stanzaChannel_->onPresenceReceived(highPresence);
		accountPresence = presenceOracle_->getAccountPresence(from);
		CPPUNIT_ASSERT_EQUAL(StatusShow::Online, accountPresence->getShow());

		stanzaChannel_->onPresenceReceived(highPresenceOffline);

		// After this, the roster should show the low presence.
		ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
		CPPUNIT_ASSERT(item);

		Presence::ref low = presenceOracle_->getAccountPresence(from);

		CPPUNIT_ASSERT_EQUAL(Presence::Available, low->getType());
		CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), low->getStatus());
		CPPUNIT_ASSERT_EQUAL(lowPresence->getShow(), item->getStatusShow());
		CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), item->getStatusText());
		stanzaChannel_->onPresenceReceived(lowPresenceOffline);
		item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
		CPPUNIT_ASSERT(item);
		/* A verification that if the test fails, it's the RosterController, not the PresenceOracle. */
		low = presenceOracle_->getHighestPriorityPresence(from);
		CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, low->getType());
		CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), low->getStatus());
		CPPUNIT_ASSERT_EQUAL(StatusShow::None, item->getStatusShow());
		CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), item->getStatusText());
	}
Ejemplo n.º 2
0
    bool operator()(const Presence::ref& a, const Presence::ref& b) {
        int aPreference = preferenceFromStatusShow(a->getShow());
        int bPreference = preferenceFromStatusShow(b->getShow());

        if (aPreference != bPreference) {
            return aPreference < bPreference;
        }
        if (a->getPriority() != b->getPriority()) {
            return a->getPriority() < b->getPriority();
        }
        return a->getFrom().getResource() < b->getFrom().getResource();
    }
Ejemplo n.º 3
0
Contact::ref UserSearchController::convertJIDtoContact(const JID& jid) {
    Contact::ref contact = std::make_shared<Contact>();
    contact->jid = jid;

    // name lookup
    boost::optional<XMPPRosterItem> rosterItem = rosterController_->getItem(jid);
    if (rosterItem && !rosterItem->getName().empty()) {
        contact->name = rosterItem->getName();
    } else {
        VCard::ref vcard = vcardManager_->getVCard(jid);
        if (vcard && !vcard->getFullName().empty()) {
            contact->name = vcard->getFullName();
        } else {
            contact->name = jid.toString();
        }
    }

    // presence lookup
    Presence::ref presence = presenceOracle_->getAccountPresence(jid);
    if (presence) {
        contact->statusType = presence->getShow();
    } else {
        contact->statusType = StatusShow::None;
    }

    // avatar lookup
    contact->avatarPath = avatarManager_->getAvatarPath(jid);
    return contact;
}
Ejemplo n.º 4
0
Presence::ref PresenceOracle::getHighestPriorityPresence(const JID& bareJID) const {
    PresencesMap::const_iterator i = entries_.find(bareJID);
    if (i == entries_.end()) {
        return Presence::ref();
    }
    Presence::ref highest;
    for (const auto& jidPresence : i->second) {
        Presence::ref current = jidPresence.second;
        if (!highest
                || current->getPriority() > highest->getPriority()
                || (current->getPriority() == highest->getPriority()
                        && StatusShow::typeToAvailabilityOrdering(current->getShow()) > StatusShow::typeToAvailabilityOrdering(highest->getShow()))) {
            highest = current;
        }
    }
    return highest;
}