summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Sluift/SluiftClient.cpp15
-rw-r--r--Sluift/SluiftClient.h10
-rw-r--r--Sluift/client.cpp27
3 files changed, 50 insertions, 2 deletions
diff --git a/Sluift/SluiftClient.cpp b/Sluift/SluiftClient.cpp
index 5243ed0..99892a9 100644
--- a/Sluift/SluiftClient.cpp
+++ b/Sluift/SluiftClient.cpp
@@ -32,18 +32,21 @@ SluiftClient::SluiftClient(
eventLoop(eventLoop),
tracer(nullptr) {
client = new Client(jid, password, networkFactories);
client->setAlwaysTrustCertificates();
client->onDisconnected.connect(boost::bind(&SluiftClient::handleDisconnected, this, _1));
client->onMessageReceived.connect(boost::bind(&SluiftClient::handleIncomingMessage, this, _1));
client->onPresenceReceived.connect(boost::bind(&SluiftClient::handleIncomingPresence, this, _1));
client->getPubSubManager()->onEvent.connect(boost::bind(&SluiftClient::handleIncomingPubSubEvent, this, _1, _2));
client->getRoster()->onInitialRosterPopulated.connect(boost::bind(&SluiftClient::handleInitialRosterPopulated, this));
+ client->getRoster()->onJIDAdded.connect(boost::bind(&SluiftClient::handleIncomingRosterAdd, this, _1));
+ client->getRoster()->onJIDRemoved.connect(boost::bind(&SluiftClient::handleIncomingRosterRemove, this, _1));
+ client->getRoster()->onJIDUpdated.connect(boost::bind(&SluiftClient::handleIncomingRosterUpdate, this, _1));
client->getClientBlockListManager()->getBlockList()->onItemAdded.connect(boost::bind(&SluiftClient::handleIncomingBlockEvent, this, _1));
client->getClientBlockListManager()->getBlockList()->onItemRemoved.connect(boost::bind(&SluiftClient::handleIncomingUnblockEvent, this, _1));
}
SluiftClient::~SluiftClient() {
delete tracer;
delete client;
}
@@ -186,18 +189,30 @@ void SluiftClient::handleIncomingBlockEvent(const JID& item) {
void SluiftClient::handleIncomingUnblockEvent(const JID& item) {
pendingEvents.push_back(Event(item, Event::UnblockEventType));
}
void SluiftClient::handleInitialRosterPopulated() {
rosterReceived = true;
}
+void SluiftClient::handleIncomingRosterAdd(const JID& item) {
+ pendingEvents.push_back(Event(item, Event::RosterAddType));
+}
+
+void SluiftClient::handleIncomingRosterRemove(const JID& item) {
+ pendingEvents.push_back(Event(item, Event::RosterRemoveType));
+}
+
+void SluiftClient::handleIncomingRosterUpdate(const JID& item) {
+ pendingEvents.push_back(Event(item, Event::RosterUpdateType));
+}
+
void SluiftClient::handleRequestResponse(std::shared_ptr<Payload> response, std::shared_ptr<ErrorPayload> error) {
requestResponse = response;
requestError = error;
requestResponseReceived = true;
}
void SluiftClient::handleDisconnected(const boost::optional<ClientError>& error) {
disconnectedError = error;
}
diff --git a/Sluift/SluiftClient.h b/Sluift/SluiftClient.h
index 39ff0a8..ac4c582 100644
--- a/Sluift/SluiftClient.h
+++ b/Sluift/SluiftClient.h
@@ -39,35 +39,38 @@ namespace Swift {
class SluiftClient {
public:
struct Event {
enum Type {
MessageType,
PresenceType,
PubSubEventType,
BlockEventType,
- UnblockEventType
+ UnblockEventType,
+ RosterAddType,
+ RosterRemoveType,
+ RosterUpdateType
};
Event(std::shared_ptr<Message> stanza) : type(MessageType), stanza(stanza) {}
Event(std::shared_ptr<Presence> stanza) : type(PresenceType), stanza(stanza) {}
Event(const JID& from, std::shared_ptr<PubSubEventPayload> payload) : type(PubSubEventType), from(from), pubsubEvent(payload) {}
Event(const JID& item, Type type) : type(type), item(item) {}
Type type;
// Message & Presence
std::shared_ptr<Stanza> stanza;
// PubSubEvent
JID from;
std::shared_ptr<PubSubEventPayload> pubsubEvent;
- // Blocklist
+ // Blocklist & Roster Push
JID item;
};
SluiftClient(
const JID& jid,
const std::string& password,
NetworkFactories* networkFactories,
SimpleEventLoop* eventLoop);
~SluiftClient();
@@ -116,18 +119,21 @@ namespace Swift {
private:
Sluift::Response doSendRequest(std::shared_ptr<Request> request, int timeout);
void handleIncomingMessage(std::shared_ptr<Message> stanza);
void handleIncomingPresence(std::shared_ptr<Presence> stanza);
void handleIncomingPubSubEvent(const JID& from, std::shared_ptr<PubSubEventPayload> event);
void handleIncomingBlockEvent(const JID& item);
void handleIncomingUnblockEvent(const JID& item);
void handleInitialRosterPopulated();
+ void handleIncomingRosterAdd(const JID& item);
+ void handleIncomingRosterRemove(const JID& item);
+ void handleIncomingRosterUpdate(const JID& item);
void handleRequestResponse(std::shared_ptr<Payload> response, std::shared_ptr<ErrorPayload> error);
void handleDisconnected(const boost::optional<ClientError>& error);
private:
NetworkFactories* networkFactories;
SimpleEventLoop* eventLoop;
Client* client;
ClientOptions options;
ClientXMLTracer* tracer;
diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index ec208bc..24ece85 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -593,18 +593,45 @@ static void pushEvent(lua_State* L, const SluiftClient::Event& event) {
}
case SluiftClient::Event::UnblockEventType: {
Lua::Table result = boost::assign::map_list_of
("type", std::make_shared<Lua::Value>(std::string("unblock")))
("jid", std::make_shared<Lua::Value>(event.item.toString()));
Lua::pushValue(L, result);
Lua::registerTableToString(L, -1);
break;
}
+ case SluiftClient::Event::RosterAddType: {
+ Lua::Table result = boost::assign::map_list_of
+ ("type", std::make_shared<Lua::Value>(std::string("rosterpush")))
+ ("jid", std::make_shared<Lua::Value>(event.item.toString()))
+ ("action", std::make_shared<Lua::Value>(std::string("added")));
+ Lua::pushValue(L, result);
+ Lua::registerTableToString(L, -1);
+ break;
+ }
+ case SluiftClient::Event::RosterRemoveType: {
+ Lua::Table result = boost::assign::map_list_of
+ ("type", std::make_shared<Lua::Value>(std::string("rosterpush")))
+ ("jid", std::make_shared<Lua::Value>(event.item.toString()))
+ ("action", std::make_shared<Lua::Value>(std::string("removed")));
+ Lua::pushValue(L, result);
+ Lua::registerTableToString(L, -1);
+ break;
+ }
+ case SluiftClient::Event::RosterUpdateType: {
+ Lua::Table result = boost::assign::map_list_of
+ ("type", std::make_shared<Lua::Value>(std::string("rosterpush")))
+ ("jid", std::make_shared<Lua::Value>(event.item.toString()))
+ ("action", std::make_shared<Lua::Value>(std::string("updated")));
+ Lua::pushValue(L, result);
+ Lua::registerTableToString(L, -1);
+ break;
+ }
}
}
struct CallUnaryLuaPredicateOnEvent {
CallUnaryLuaPredicateOnEvent(lua_State* L, int index) : L(L), index(index) {
}
bool operator()(const SluiftClient::Event& event) {
lua_pushvalue(L, index);