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
 
@@ -57,12 +57,14 @@ class RosterManager {
 
		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
include/transport/usermanager.h
Show inline comments
 
@@ -81,9 +81,10 @@ class UserManager {
 
		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
 
@@ -156,7 +156,21 @@ void RosterManager::setStorageBackend(StorageBackend *storageBackend) {
 
		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
 
@@ -21,12 +21,15 @@
 
#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 {
 

	
 
@@ -38,15 +41,33 @@ RosterResponder::RosterResponder(Swift::IQRouter *router, StorageBackend *storag
 
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)