summaryrefslogtreecommitdiffstats
path: root/Sluift
diff options
context:
space:
mode:
authorRoger Planas <roger.planas@isode.com>2017-01-30 12:34:13 (GMT)
committerRoger Planas <roger.planas@isode.com>2017-01-31 09:38:27 (GMT)
commitf4599f51c153dc59cd074bbd212b9c17347cd05b (patch)
treedaac9bd2215d9e4cf3967fc85785fecd05561f94 /Sluift
parentf3e46add7f512180833f91c3442ee9fb059b5f0c (diff)
downloadswift-f4599f51c153dc59cd074bbd212b9c17347cd05b.zip
swift-f4599f51c153dc59cd074bbd212b9c17347cd05b.tar.bz2
Sluift: Add client methods for adding and removing JIDs from blocklist
A previous commit added a get_block_list() client method to retrieve the list of blocked items. This patch extends that and adds capabilities to add and remove items to such list. Test-information: Tested with client and was able to successfully add items to list, delete and delete all Also tried to delete a non existing item and it rightly complained. Change-Id: Iabbfdbd9e74ddc9740db5c9871b8355210aa0727
Diffstat (limited to 'Sluift')
-rw-r--r--Sluift/client.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index 53e253f..d2b50fa 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -197,60 +197,106 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
("jid", std::make_shared<Lua::Value>(item.getJID().toString()))
("name", std::make_shared<Lua::Value>(item.getName()))
("subscription", std::make_shared<Lua::Value>(subscription))
("groups", std::make_shared<Lua::Value>(std::vector<Lua::Value>(item.getGroups().begin(), item.getGroups().end())));
contactsTable[item.getJID().toString()] = std::make_shared<Lua::Value>(itemTable);
}
pushValue(L, contactsTable);
Lua::registerTableToString(L, -1);
return 1;
}
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, add_block,
+ "Adds a user or domain to the blocking list.",
+ "self\n",
+ "jid the JID of the user or domain to add to the blocking list\n"
+
+) {
+ SluiftClient* client = getClient(L);
+ JID jid(Lua::checkString(L, 2));
+ int timeout = getGlobalTimeout(L);
+
+ std::shared_ptr<BlockPayload> payload = std::make_shared<BlockPayload>(std::vector<JID>(1, jid));
+ return client->sendRequest(
+ std::make_shared< GenericRequest<BlockPayload> >(IQ::Set, JID(), payload, client->getClient()->getIQRouter()), timeout).convertToLuaResult(L);
+}
+
+SLUIFT_LUA_FUNCTION_WITH_HELP(
+ Client, remove_block,
+ "Removes a user or domain from the blocking list.",
+ "self\n",
+ "jid the JID of the user or domain to remove from the blocking list\n"
+
+) {
+ SluiftClient* client = getClient(L);
+ JID jid(Lua::checkString(L, 2));
+ int timeout = getGlobalTimeout(L);
+
+ std::shared_ptr<UnblockPayload> payload = std::make_shared<UnblockPayload>(std::vector<JID>(1, jid));
+ return client->sendRequest(
+ std::make_shared< GenericRequest<UnblockPayload> >(IQ::Set, JID(), payload, client->getClient()->getIQRouter()), timeout).convertToLuaResult(L);
+}
+
+SLUIFT_LUA_FUNCTION_WITH_HELP(
+ Client, remove_all_block,
+ "Removes all users and domains from the blocking list.",
+ "self\n",
+ ""
+) {
+ SluiftClient* client = getClient(L);
+ int timeout = getGlobalTimeout(L);
+
+ std::shared_ptr<UnblockPayload> payload = std::make_shared<UnblockPayload>(std::vector<JID>());
+ return client->sendRequest(
+ std::make_shared< GenericRequest<UnblockPayload> >(IQ::Set, JID(), payload, client->getClient()->getIQRouter()), timeout).convertToLuaResult(L);
+}
+
+SLUIFT_LUA_FUNCTION_WITH_HELP(
Client, send_message,
"Send a message.",
"self\n"
"to the JID to send the message to\n"
"body the body of the message. Can alternatively be specified using the `body` option\n",
"to the JID to send the message to\n"
"body the body of the message\n"
"subject the subject of the MUC room to set\n"
"type the type of message to send (`normal`, `chat`, `error`, `groupchat`, `headline`)\n"
"payloads payloads to add to the message\n"
) {
Sluift::globals.eventLoop.runOnce();
JID to;
boost::optional<std::string> body;
boost::optional<std::string> subject;
std::vector<std::shared_ptr<Payload> > payloads;
int index = 2;
Message::Type type = Message::Chat;
if (lua_isstring(L, index)) {
to = std::string(lua_tostring(L, index));
++index;
if (lua_isstring(L, index)) {
body = lua_tostring(L, index);
++index;
}
}
if (lua_istable(L, index)) {
if (boost::optional<std::string> value = Lua::getStringField(L, index, "to")) {
to = *value;