From ab06275bbcc1278d2e2d924b4e3d52988e27c30b Mon Sep 17 00:00:00 2001 From: Roger Planas Date: Tue, 28 Jan 2014 11:42:23 +0000 Subject: Sluift: Add shortcut for 'subject' to send_message Change-Id: I4343c98d34a70998f25852f05cf1d95458882541 diff --git a/Sluift/client.cpp b/Sluift/client.cpp index 06ce807..e2ba480 100644 --- a/Sluift/client.cpp +++ b/Sluift/client.cpp @@ -213,14 +213,17 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( "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; - std::string body; + boost::optional body; + boost::optional subject; std::vector > payloads; int index = 2; Message::Type type = Message::Chat; @@ -238,7 +241,7 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( } if (boost::optional value = Lua::getStringField(L, index, "body")) { - body = *value; + body = value; } if (boost::optional value = Lua::getStringField(L, index, "type")) { @@ -259,21 +262,29 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( } } + if (boost::optional value = Lua::getStringField(L, index, "subject")) { + subject = value; + } + payloads = getPayloadsFromTable(L, index); } if (!to.isValid()) { throw Lua::Exception("Missing 'to'"); } - if (body.empty()) { - throw Lua::Exception("Missing 'body'"); + if ((!body || body->empty()) && !subject && payloads.empty()) { + throw Lua::Exception("Missing any of 'body', 'subject' or 'payloads'"); } - Message::ref message = boost::make_shared(); message->setTo(to); - message->setBody(body); - message->setType(type); + if (body && !body->empty()) { + message->setBody(*body); + } + if (subject) { + message->setSubject(*subject); + } message->addPayloads(payloads.begin(), payloads.end()); + message->setType(type); getClient(L)->getClient()->sendMessage(message); return 0; } -- cgit v0.10.2-6-g49f6