Create buddies from database cache, handle jabber:iq:roster sets.
This commit is contained in:
parent
448a9173df
commit
525a07a4d1
9 changed files with 52 additions and 18 deletions
|
@ -48,7 +48,6 @@ namespace Transport {
|
|||
class StorageBackend;
|
||||
class DiscoInfoResponder;
|
||||
class DiscoItemsResponder;
|
||||
class RosterResponder;
|
||||
class Factory;
|
||||
|
||||
/// Represents one transport instance.
|
||||
|
@ -155,7 +154,6 @@ namespace Transport {
|
|||
StorageBackend *m_storageBackend;
|
||||
DiscoInfoResponder *m_discoInfoResponder;
|
||||
DiscoItemsResponder *m_discoItemsResponder;
|
||||
RosterResponder *m_rosterResponder;
|
||||
int m_reconnectCount;
|
||||
Config* m_config;
|
||||
std::string m_protocol;
|
||||
|
|
|
@ -30,6 +30,7 @@ class User;
|
|||
class Component;
|
||||
class StorageBackend;
|
||||
class StorageResponder;
|
||||
class RosterResponder;
|
||||
|
||||
/// Manages online XMPP Users.
|
||||
|
||||
|
@ -82,6 +83,7 @@ class UserManager {
|
|||
Component *m_component;
|
||||
StorageBackend *m_storageBackend;
|
||||
StorageResponder *m_storageResponder;
|
||||
RosterResponder *m_rosterResponder;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -62,7 +62,13 @@ class NetworkFactory : public Factory {
|
|||
}
|
||||
|
||||
Buddy *createBuddy(RosterManager *rosterManager, const BuddyInfo &buddyInfo) {
|
||||
return new LocalBuddy(rosterManager, -1);
|
||||
LocalBuddy *buddy = new LocalBuddy(rosterManager, buddyInfo.id);
|
||||
buddy->setAlias(buddyInfo.alias);
|
||||
buddy->setName(buddyInfo.legacyName);
|
||||
buddy->setSubscription(buddyInfo.subscription);
|
||||
buddy->setGroups(buddyInfo.groups);
|
||||
buddy->setFlags((BuddyFlag) buddyInfo.flags);
|
||||
return buddy;
|
||||
}
|
||||
private:
|
||||
NetworkPluginServer *m_nps;
|
||||
|
|
|
@ -39,6 +39,9 @@ RosterManager::RosterManager(User *user, Component *component){
|
|||
m_setBuddyTimer = m_component->getFactories()->getTimerFactory()->createTimer(1000);
|
||||
m_RIETimer = m_component->getFactories()->getTimerFactory()->createTimer(5000);
|
||||
m_RIETimer->onTick.connect(boost::bind(&RosterManager::sendRIE, this));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
RosterManager::~RosterManager() {
|
||||
|
@ -144,6 +147,16 @@ void RosterManager::setStorageBackend(StorageBackend *storageBackend) {
|
|||
delete m_rosterStorage;
|
||||
}
|
||||
m_rosterStorage = new RosterStorage(m_user, 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,9 @@ using namespace boost;
|
|||
|
||||
namespace Transport {
|
||||
|
||||
RosterResponder::RosterResponder(Swift::IQRouter *router) : Swift::GetResponder<RosterPayload>(router) {
|
||||
RosterResponder::RosterResponder(Swift::IQRouter *router, StorageBackend *storageBackend, UserManager *userManager) : Swift::Responder<RosterPayload>(router) {
|
||||
m_storageBackend = storageBackend;
|
||||
m_userManager = userManager;
|
||||
}
|
||||
|
||||
RosterResponder::~RosterResponder() {
|
||||
|
@ -43,4 +45,9 @@ bool RosterResponder::handleGetRequest(const Swift::JID& from, const Swift::JID&
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,18 +22,24 @@
|
|||
|
||||
#include <vector>
|
||||
#include "Swiften/Swiften.h"
|
||||
#include "Swiften/Queries/GetResponder.h"
|
||||
#include "Swiften/Queries/Responder.h"
|
||||
#include "Swiften/Elements/RosterPayload.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
class RosterResponder : public Swift::GetResponder<Swift::RosterPayload> {
|
||||
class StorageBackend;
|
||||
class UserManager;
|
||||
|
||||
class RosterResponder : public Swift::Responder<Swift::RosterPayload> {
|
||||
public:
|
||||
RosterResponder(Swift::IQRouter *router);
|
||||
RosterResponder(Swift::IQRouter *router, StorageBackend *storageBackend, UserManager *userManager);
|
||||
~RosterResponder();
|
||||
|
||||
private:
|
||||
virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::RosterPayload> payload);
|
||||
virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::RosterPayload> payload);
|
||||
StorageBackend *m_storageBackend;
|
||||
UserManager *m_userManager;
|
||||
};
|
||||
|
||||
}
|
|
@ -48,6 +48,7 @@
|
|||
|
||||
#define BIND_INT(STATEMENT, VARIABLE) sqlite3_bind_int(STATEMENT, STATEMENT##_id++, VARIABLE)
|
||||
#define BIND_STR(STATEMENT, VARIABLE) sqlite3_bind_text(STATEMENT, STATEMENT##_id++, VARIABLE.c_str(), -1, SQLITE_STATIC)
|
||||
#define RESET_GET_COUNTER(STATEMENT) STATEMENT##_id_get = 0;
|
||||
#define GET_INT(STATEMENT) sqlite3_column_int(STATEMENT, STATEMENT##_id_get++)
|
||||
#define GET_STR(STATEMENT) (const char *) sqlite3_column_text(STATEMENT, STATEMENT##_id_get++)
|
||||
#define EXECUTE_STATEMENT(STATEMENT, NAME) if(sqlite3_step(STATEMENT) != SQLITE_DONE) {\
|
||||
|
@ -111,7 +112,7 @@ bool SQLite3Backend::connect() {
|
|||
|
||||
PREP_STMT(m_addBuddy, "INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
PREP_STMT(m_updateBuddy, "UPDATE " + m_prefix + "buddies SET groups=?, nickname=?, flags=?, subscription=? WHERE user_id=? AND uin=?");
|
||||
PREP_STMT(m_getBuddies, "SELECT id uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC");
|
||||
PREP_STMT(m_getBuddies, "SELECT id, uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC");
|
||||
PREP_STMT(m_getBuddiesSettings, "SELECT buddy_id, type, var, value FROM " + m_prefix + "buddies_settings WHERE user_id=? ORDER BY buddy_id ASC");
|
||||
PREP_STMT(m_getUserSetting, "SELECT type, value FROM " + m_prefix + "users_settings WHERE user_id=? AND var=?");
|
||||
PREP_STMT(m_setUserSetting, "INSERT INTO " + m_prefix + "users_settings (user_id, var, type, value) VALUES (?,?,?,?)");
|
||||
|
@ -261,7 +262,7 @@ void SQLite3Backend::updateBuddy(long userId, const BuddyInfo &buddyInfo) {
|
|||
}
|
||||
|
||||
bool SQLite3Backend::getBuddies(long id, std::list<BuddyInfo> &roster) {
|
||||
// "SELECT id, user_id, uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC"
|
||||
// SELECT id, uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC
|
||||
BEGIN(m_getBuddies);
|
||||
BIND_INT(m_getBuddies, id);
|
||||
|
||||
|
@ -276,6 +277,7 @@ bool SQLite3Backend::getBuddies(long id, std::list<BuddyInfo> &roster) {
|
|||
int ret;
|
||||
while((ret = sqlite3_step(m_getBuddies)) == SQLITE_ROW) {
|
||||
BuddyInfo b;
|
||||
RESET_GET_COUNTER(m_getBuddies);
|
||||
b.id = GET_INT(m_getBuddies);
|
||||
b.legacyName = GET_STR(m_getBuddies);
|
||||
b.subscription = GET_STR(m_getBuddies);
|
||||
|
@ -313,10 +315,10 @@ bool SQLite3Backend::getBuddies(long id, std::list<BuddyInfo> &roster) {
|
|||
}
|
||||
}
|
||||
|
||||
if (ret != SQLITE_DONE) {
|
||||
onStorageError("getBuddiesSettings query", (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
|
||||
return false;
|
||||
}
|
||||
// if (ret != SQLITE_DONE) {
|
||||
// onStorageError("getBuddiesSettings query", (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
|
||||
// return false;
|
||||
// }
|
||||
|
||||
roster.push_back(b);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "transport/factory.h"
|
||||
#include "discoinforesponder.h"
|
||||
#include "discoitemsresponder.h"
|
||||
#include "rosterresponder.h"
|
||||
#include "storageparser.h"
|
||||
|
||||
using namespace Swift;
|
||||
|
@ -96,9 +95,6 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) {
|
|||
m_discoItemsResponder = new DiscoItemsResponder(m_iqRouter);
|
||||
m_discoItemsResponder->start();
|
||||
|
||||
m_rosterResponder = new RosterResponder(m_iqRouter);
|
||||
m_rosterResponder->start();
|
||||
|
||||
//
|
||||
// m_registerHandler = new SpectrumRegisterHandler(m_component);
|
||||
// m_registerHandler->start();
|
||||
|
@ -109,7 +105,6 @@ Component::~Component() {
|
|||
delete m_entityCapsManager;
|
||||
delete m_capsManager;
|
||||
delete m_capsMemoryStorage;
|
||||
delete m_rosterResponder;
|
||||
delete m_discoInfoResponder;
|
||||
if (m_component)
|
||||
delete m_component;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "transport/conversationmanager.h"
|
||||
#include "transport/rostermanager.h"
|
||||
#include "storageresponder.h"
|
||||
#include "rosterresponder.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
|
@ -37,6 +38,9 @@ UserManager::UserManager(Component *component, StorageBackend *storageBackend) {
|
|||
m_storageResponder = new StorageResponder(component->getIQRouter(), m_storageBackend, this);
|
||||
m_storageResponder->start();
|
||||
|
||||
m_rosterResponder = new RosterResponder(component->getIQRouter(), m_storageBackend, this);
|
||||
m_rosterResponder->start();
|
||||
|
||||
component->onUserPresenceReceived.connect(bind(&UserManager::handlePresence, this, _1));
|
||||
m_component->getStanzaChannel()->onMessageReceived.connect(bind(&UserManager::handleMessageReceived, this, _1));
|
||||
m_component->getStanzaChannel()->onPresenceReceived.connect(bind(&UserManager::handleGeneralPresenceReceived, this, _1));
|
||||
|
@ -46,6 +50,7 @@ UserManager::UserManager(Component *component, StorageBackend *storageBackend) {
|
|||
UserManager::~UserManager(){
|
||||
m_storageResponder->stop();
|
||||
delete m_storageResponder;
|
||||
delete m_rosterResponder;
|
||||
}
|
||||
|
||||
void UserManager::addUser(User *user) {
|
||||
|
|
Loading…
Add table
Reference in a new issue