From f4599f51c153dc59cd074bbd212b9c17347cd05b Mon Sep 17 00:00:00 2001
From: Roger Planas <roger.planas@isode.com>
Date: Mon, 30 Jan 2017 12:34:13 +0000
Subject: 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

diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index 53e253f..d2b50fa 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -224,6 +224,52 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
 }
 
 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"
-- 
cgit v0.10.2-6-g49f6