summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;