summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger Planas <roger.planas@isode.com>2017-01-17 14:42:38 (GMT)
committerTobias Markmann <tm@ayena.de>2017-01-27 16:17:52 (GMT)
commitf3e46add7f512180833f91c3442ee9fb059b5f0c (patch)
treec20ba2d617be8c1c7092e598b3f879b0565cdb57 /Sluift/client.cpp
parentfa068e62cbf70d93296de7887cbcfdda5d36d2b2 (diff)
downloadswift-f3e46add7f512180833f91c3442ee9fb059b5f0c.zip
swift-f3e46add7f512180833f91c3442ee9fb059b5f0c.tar.bz2
Sluift: Add handling of block/unblock events
Swiften handles blocklist event notifications, but those were not passed to Sluift, so a Sluift client, when querying events, would not be aware if an XMPP server pushes block/unblock. This patch adds an extra event type to Sluift so that method for_each_event reports block/unblock notifications, in addition to a new API 'get_block_list' to retrieve the blocklist from the server. Test-information: Used Sluift client to retrieve blocklist and it is as expected. Also used client to retrieve all items after adding, removing and removing all items in the blocklist, and Sluift clients can now see these events. Change-Id: I0b76289ebd9e63505ff8a99cd9c0aa0e93af0c22
Diffstat (limited to 'Sluift/client.cpp')
-rw-r--r--Sluift/client.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index 186effc..53e253f 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2016 Isode Limited.
+ * Copyright (c) 2013-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -206,6 +206,24 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
}
SLUIFT_LUA_FUNCTION_WITH_HELP(
+ Client, get_block_list,
+ "Returns a table of all the items in the blocking list.",
+ "self\n",
+ ""
+) {
+ Sluift::globals.eventLoop.runOnce();
+ SluiftClient* client = getClient(L);
+ lua_newtable(L);
+ int i = 0;
+ for (const auto& item : client->getBlockList(getGlobalTimeout(L))) {
+ lua_pushstring(L, item.toString().c_str());
+ lua_rawseti(L, -2, boost::numeric_cast<int>(++i));
+ }
+ Lua::registerTableToString(L, -1);
+ return 1;
+}
+
+SLUIFT_LUA_FUNCTION_WITH_HELP(
Client, send_message,
"Send a message.",
"self\n"
@@ -518,6 +536,23 @@ static void pushEvent(lua_State* L, const SluiftClient::Event& event) {
lua_pushvalue(L, -3);
lua_call(L, 1, 0);
lua_pop(L, 1);
+ break;
+ }
+ case SluiftClient::Event::BlockEventType: {
+ Lua::Table result = boost::assign::map_list_of
+ ("type", std::make_shared<Lua::Value>(std::string("block")))
+ ("jid", std::make_shared<Lua::Value>(event.item.toString()));
+ Lua::pushValue(L, result);
+ Lua::registerTableToString(L, -1);
+ break;
+ }
+ 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;
}
}
}