Supported RIE in component mode

This commit is contained in:
HanzZ 2011-04-04 23:26:05 +02:00
parent 63a7b8eef5
commit 5438bada5d
3 changed files with 36 additions and 1 deletions

View file

@ -72,12 +72,15 @@ class RosterManager {
void setBuddyCallback(Buddy *buddy);
void sendBuddyRosterPush(Buddy *buddy);
void sendRIE();
void handleBuddyRosterPushResponse(Swift::ErrorPayload::ref error, const std::string &key);
std::map<std::string, Buddy *> m_buddies;
Component *m_component;
User *m_user;
Swift::Timer::ref m_setBuddyTimer;
Swift::Timer::ref m_RIETimer;
};
}

View file

@ -2,7 +2,7 @@
jid = icq.localhost
password = secret
server = 127.0.0.1
port = 5222
port = 8888
protocol=prpl-jabber
server_mode=1

View file

@ -26,6 +26,7 @@
#include "Swiften/Roster/SetRosterRequest.h"
#include "Swiften/Elements/RosterPayload.h"
#include "Swiften/Elements/RosterItemPayload.h"
#include "Swiften/Elements/RosterItemExchangePayload.h"
namespace Transport {
@ -33,9 +34,13 @@ RosterManager::RosterManager(User *user, Component *component){
m_user = user;
m_component = component;
m_setBuddyTimer = m_component->getFactories()->getTimerFactory()->createTimer(1000);
m_RIETimer = m_component->getFactories()->getTimerFactory()->createTimer(3000);
m_RIETimer->onTick.connect(boost::bind(&RosterManager::sendRIE, this));
}
RosterManager::~RosterManager() {
m_setBuddyTimer->stop();
m_RIETimer->stop();
}
void RosterManager::setBuddy(Buddy *buddy) {
@ -63,12 +68,20 @@ void RosterManager::setBuddyCallback(Buddy *buddy) {
m_buddies[buddy->getName()] = buddy;
onBuddySet(buddy);
// In server mode the only way is to send jabber:iq:roster push.
// In component mode we send RIE or Subscribe presences, based on features.
if (m_component->inServerMode()) {
sendBuddyRosterPush(buddy);
}
else {
}
if (m_setBuddyTimer->onTick.empty()) {
m_setBuddyTimer->stop();
if (true /*&& rie_is_supported*/) {
m_RIETimer->start();
}
}
}
@ -87,4 +100,23 @@ Buddy *RosterManager::getBuddy(const std::string &name) {
return m_buddies[name];
}
void RosterManager::sendRIE() {
m_RIETimer->stop();
Swift::RosterItemExchangePayload::ref payload = Swift::RosterItemExchangePayload::ref(new Swift::RosterItemExchangePayload());
for (std::map<std::string, Buddy *>::const_iterator it = m_buddies.begin(); it != m_buddies.end(); it++) {
Buddy *buddy = (*it).second;
Swift::RosterItemExchangePayload::Item item;
item.jid = buddy->getJID().toBare();
item.name = buddy->getAlias();
item.action = Swift::RosterItemExchangePayload::Add;
item.groups = buddy->getGroups();
payload->addItem(item);
}
boost::shared_ptr<Swift::GenericRequest<Swift::RosterItemExchangePayload> > request(new Swift::GenericRequest<Swift::RosterItemExchangePayload>(Swift::IQ::Set, m_user->getJID(), payload, m_component->getIQRouter()));
request->send();
}
}