Changeset - 8ab47cce7012
[Not reviewed]
0 5 0
HanzZ - 14 years ago 2011-05-31 16:01:17
hanzz.k@gmail.com
Answer to initial jabber:iq:roster get
4 files changed with 38 insertions and 0 deletions:
0 comments (0 inline, 0 general)
include/transport/rostermanager.h
Show inline comments
 
@@ -51,24 +51,26 @@ class RosterManager {
 
		/// the buddy is added to server-side roster using remote-roster protoXEP).
 
		/// \param buddy Buddy
 
		void setBuddy(Buddy *buddy);
 

	
 
		/// Deassociates the buddy with this roster.
 
		/// \param buddy Buddy.
 
		void unsetBuddy(Buddy *buddy);
 

	
 
		Buddy *getBuddy(const std::string &name);
 

	
 
		void setStorageBackend(StorageBackend *storageBackend);
 

	
 
		Swift::RosterPayload::ref generateRosterPayload();
 

	
 
		/// Returns user associated with this roster.
 
		/// \return User
 
		User *getUser() { return m_user; }
 

	
 
		/// Called when new Buddy is added to this roster.
 
		/// \param buddy newly added Buddy
 
		boost::signal<void (Buddy *buddy)> onBuddySet;
 

	
 
		/// Called when Buddy has been removed from this roster.
 
		/// \param buddy removed Buddy
 
		boost::signal<void (Buddy *buddy)> onBuddyUnset;
 

	
include/transport/usermanager.h
Show inline comments
 
@@ -75,15 +75,16 @@ class UserManager {
 
		void handleProbePresence(Swift::Presence::ref presence);
 
		void handleSubscription(Swift::Presence::ref presence);
 
// 		void handleDiscoInfoResponse(boost::shared_ptr<Swift::DiscoInfo> info, Swift::ErrorPayload::ref error, const Swift::JID& jid);
 
		void addUser(User *user);
 

	
 
		long m_onlineBuddies;
 
		User *m_cachedUser;
 
		std::map<std::string, User *> m_users;
 
		Component *m_component;
 
		StorageBackend *m_storageBackend;
 
		StorageResponder *m_storageResponder;
 
		RosterResponder *m_rosterResponder;
 
		friend class RosterResponder;
 
};
 

	
 
}
src/rostermanager.cpp
Show inline comments
 
@@ -150,13 +150,27 @@ void RosterManager::setStorageBackend(StorageBackend *storageBackend) {
 

	
 
	std::list<BuddyInfo> roster;
 
	storageBackend->getBuddies(m_user->getUserInfo().id, roster);
 

	
 
	for (std::list<BuddyInfo>::const_iterator it = roster.begin(); it != roster.end(); it++) {
 
		Buddy *buddy = m_component->getFactory()->createBuddy(this, *it);
 
		std::cout << "CREATING BUDDY FROM DATABASE CACHE " << buddy->getName() << "\n";
 
		m_buddies[buddy->getName()] = buddy;
 
		onBuddySet(buddy);
 
	}
 
}
 

	
 
Swift::RosterPayload::ref RosterManager::generateRosterPayload() {
 
	Swift::RosterPayload::ref payload = Swift::RosterPayload::ref(new Swift::RosterPayload());
 

	
 
	for (std::map<std::string, Buddy *>::const_iterator it = m_buddies.begin(); it != m_buddies.end(); it++) {
 
		Buddy *buddy = (*it).second;
 
		Swift::RosterItemPayload item;
 
		item.setJID(buddy->getJID().toBare());
 
		item.setName(buddy->getAlias());
 
		item.setGroups(buddy->getGroups());
 
		payload->addItem(item);
 
	}
 
	return payload;
 
}
 

	
 
}
src/rosterresponder.cpp
Show inline comments
 
@@ -15,39 +15,60 @@
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "rosterresponder.h"
 

	
 
#include <iostream>
 
#include <boost/bind.hpp>
 
#include "Swiften/Queries/IQRouter.h"
 
#include "Swiften/Swiften.h"
 
#include "transport/user.h"
 
#include "transport/usermanager.h"
 
#include "transport/rostermanager.h"
 

	
 
using namespace Swift;
 
using namespace boost;
 

	
 
namespace Transport {
 

	
 
RosterResponder::RosterResponder(Swift::IQRouter *router, StorageBackend *storageBackend, UserManager *userManager) : Swift::Responder<RosterPayload>(router) {
 
	m_storageBackend = storageBackend;
 
	m_userManager = userManager;
 
}
 

	
 
RosterResponder::~RosterResponder() {
 
}
 

	
 
bool RosterResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::RosterPayload> payload) {
 
	// Get means we're in server mode and user wants to fetch his roster.
 
	// For now we send empty reponse, but TODO: Get buddies from database and send proper stored roster.
 
	User *user = m_userManager->getUser(from.toBare().toString());
 
	if (!user) {
 
		// Client can send jabber:iq:roster IQ before presence, so we do little hack here to
 
		// trigger logging in.
 
		// UserManager should create user now, if everything is OK.
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo(to);
 
		response->setFrom(from);
 
		response->setType(Swift::Presence::Available);
 
		m_userManager->handlePresence(response);
 

	
 
		// if it's not created, lets finish this get
 
		user = m_userManager->getUser(from.toBare().toString());
 
		if (!user) {
 
			sendResponse(from, id, boost::shared_ptr<RosterPayload>(new RosterPayload()));
 
			return true;
 
		}
 
	}
 
	sendResponse(from, id, user->getRosterManager()->generateRosterPayload());
 
	return true;
 
}
 

	
 
bool RosterResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::RosterPayload> payload) {
 
	sendResponse(from, id, boost::shared_ptr<RosterPayload>(new RosterPayload()));
 
	return true;
 
}
 

	
 
}
0 comments (0 inline, 0 general)