User::getJIDWithFeature

This commit is contained in:
Jan Kaluza 2011-07-13 14:58:58 +02:00
parent 3c0e38368c
commit e2a992466e
2 changed files with 31 additions and 0 deletions

View file

@ -51,6 +51,11 @@ class User {
/// \return full JID
const Swift::JID &getJID();
/// Returns full JID which supports particular feature or invalid JID.
/// \param feature disco#info feature.
/// \return full JID which supports particular feature or invalid JID.
Swift::JID getJIDWithFeature(const std::string &feature);
/// Returns UserInfo struct with informations needed to connect the legacy network.
/// \return UserInfo struct
UserInfo &getUserInfo() { return m_userInfo; }

View file

@ -29,8 +29,12 @@
#include "Swiften/Elements/StreamError.h"
#include "Swiften/Elements/MUCPayload.h"
#include "log4cxx/logger.h"
#include <boost/foreach.hpp>
using namespace log4cxx;
using namespace boost;
#define foreach BOOST_FOREACH
namespace Transport {
@ -66,6 +70,28 @@ const Swift::JID &User::getJID() {
return m_jid;
}
Swift::JID User::getJIDWithFeature(const std::string &feature) {
Swift::JID jid;
std::vector<Swift::Presence::ref> presences = m_presenceOracle->getAllPresence(m_jid);
foreach(Swift::Presence::ref presence, presences) {
if (presence->getType() == Swift::Presence::Unavailable)
continue;
Swift::DiscoInfo::ref discoInfo = m_entityCapsManager->getCaps(presence->getFrom());
if (discoInfo)
continue;
if (discoInfo->hasFeature(feature)) {
LOG4CXX_INFO(logger, m_jid.toString() << ": Found JID with " << feature << "feature: " << presence->getFrom().toString());
return presence->getFrom();
}
}
LOG4CXX_INFO(logger, m_jid.toString() << ": No JID with " << feature << "feature");
return jid;
}
void User::handlePresence(Swift::Presence::ref presence) {
std::cout << "PRESENCE " << presence->getFrom().toString() << "\n";
if (!m_connected) {