Changeset - f1e8d126743c
[Not reviewed]
0 4 0
Jan Kaluza - 14 years ago 2011-06-14 15:12:35
hanzz.k@gmail.com
forward vcard set to backend
4 files changed with 30 insertions and 1 deletions:
0 comments (0 inline, 0 general)
include/transport/networkpluginserver.h
Show inline comments
 
@@ -77,12 +77,13 @@ class NetworkPluginServer {
 
		void handleUserDestroyed(User *user);
 

	
 
		void handleBuddyUpdated(Buddy *buddy, const Swift::RosterItemPayload &item);
 
		void handleBuddyRemoved(Buddy *buddy);
 
		void handleBuddyAdded(Buddy *buddy, const Swift::RosterItemPayload &item);
 

	
 
		void handleVCardUpdated(User *user, boost::shared_ptr<Swift::VCard> vcard);
 
		void handleVCardRequired(User *user, const std::string &name, unsigned int id);
 

	
 
		void send(boost::shared_ptr<Swift::Connection> &, const std::string &data);
 

	
 
		void pingTimeout();
 
		void sendPing(Client *c);
include/transport/vcardresponder.h
Show inline comments
 
@@ -36,12 +36,13 @@ class VCardResponder : public Swift::Responder<Swift::VCard> {
 
		VCardResponder(Swift::IQRouter *router, UserManager *userManager);
 
		~VCardResponder();
 

	
 
		void sendVCard(unsigned int id, boost::shared_ptr<Swift::VCard> vcard);
 

	
 
		boost::signal<void (User *, const std::string &name, unsigned int id)> onVCardRequired;
 
		boost::signal<void (User *, boost::shared_ptr<Swift::VCard> vcard)> onVCardUpdated;
 

	
 
	private:
 
		struct VCardData {
 
			Swift::JID from;
 
			Swift::JID to;
 
			std::string id;
src/networkpluginserver.cpp
Show inline comments
 
@@ -122,12 +122,13 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
 

	
 
	m_pingTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(10000);
 
	m_pingTimer->onTick.connect(boost::bind(&NetworkPluginServer::pingTimeout, this)); 
 

	
 
	m_vcardResponder = new VCardResponder(component->getIQRouter(), userManager);
 
	m_vcardResponder->onVCardRequired.connect(boost::bind(&NetworkPluginServer::handleVCardRequired, this, _1, _2, _3));
 
	m_vcardResponder->onVCardUpdated.connect(boost::bind(&NetworkPluginServer::handleVCardUpdated, this, _1, _2));
 
	m_vcardResponder->start();
 

	
 
	m_rosterResponder = new RosterResponder(component->getIQRouter(), userManager);
 
	m_rosterResponder->onBuddyAdded.connect(boost::bind(&NetworkPluginServer::handleBuddyAdded, this, _1, _2));
 
	m_rosterResponder->onBuddyRemoved.connect(boost::bind(&NetworkPluginServer::handleBuddyRemoved, this, _1));
 
	m_rosterResponder->onBuddyUpdated.connect(boost::bind(&NetworkPluginServer::handleBuddyUpdated, this, _1, _2));
 
@@ -652,14 +653,29 @@ void NetworkPluginServer::handleBuddyUpdated(Buddy *b, const Swift::RosterItemPa
 
}
 

	
 
void NetworkPluginServer::handleBuddyAdded(Buddy *buddy, const Swift::RosterItemPayload &item) {
 
	handleBuddyUpdated(buddy, item);
 
}
 

	
 
void NetworkPluginServer::handleVCardUpdated(User *user, boost::shared_ptr<Swift::VCard> v) {
 
	pbnetwork::VCard vcard;
 
	vcard.set_username(user->getJID().toBare());
 
	vcard.set_buddyname("");
 
	vcard.set_id(0);
 
	vcard.set_photo(&v->getPhoto()[0], v->getPhoto().size());
 

	
 
	std::string message;
 
	vcard.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_VCARD);
 

	
 
	Client *c = (Client *) user->getData();
 
	send(c->connection, message);
 
}
 

	
 
void NetworkPluginServer::handleVCardRequired(User *user, const std::string &name, unsigned int id) {
 
	std::cout << "VCARD REQUIRED " << name << " " << id << "\n";
 
	pbnetwork::VCard vcard;
 
	vcard.set_username(user->getJID().toBare());
 
	vcard.set_buddyname(name);
 
	vcard.set_id(id);
 

	
 
	std::string message;
src/vcardresponder.cpp
Show inline comments
 
@@ -70,11 +70,22 @@ bool VCardResponder::handleGetRequest(const Swift::JID& from, const Swift::JID&
 
	m_queries[m_id].id = id; 
 
	onVCardRequired(user, name, m_id++);
 
	return true;
 
}
 

	
 
bool VCardResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::VCard> payload) {
 
	if (!to.getNode().empty()) {
 
		return false;
 
	}
 

	
 
	User *user = m_userManager->getUser(from.toBare().toString());
 
	if (!user) {
 
		return false;
 
	}
 

	
 
	onVCardUpdated(user, payload);
 

	
 
	sendResponse(from, id, boost::shared_ptr<VCard>(new VCard()));
 
	return true;
 
}
 

	
 
}
0 comments (0 inline, 0 general)