summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger Planas <roger.planas@isode.com>2014-01-28 11:42:23 (GMT)
committerSwift Review <review@swift.im>2014-01-28 16:32:54 (GMT)
commitab06275bbcc1278d2e2d924b4e3d52988e27c30b (patch)
tree641490bf4e57adc838ac78a10bd55051249d721a
parent8879e4aa04bd849504d669430ccbd0ee5dbf4cc7 (diff)
downloadswift-contrib-ab06275bbcc1278d2e2d924b4e3d52988e27c30b.zip
swift-contrib-ab06275bbcc1278d2e2d924b4e3d52988e27c30b.tar.bz2
Sluift: Add shortcut for 'subject' to send_message
Change-Id: I4343c98d34a70998f25852f05cf1d95458882541
-rw-r--r--Sluift/client.cpp25
1 files changed, 18 insertions, 7 deletions
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<std::string> body;
+ boost::optional<std::string> subject;
std::vector<boost::shared_ptr<Payload> > payloads;
int index = 2;
Message::Type type = Message::Chat;
@@ -238,7 +241,7 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
}
if (boost::optional<std::string> value = Lua::getStringField(L, index, "body")) {
- body = *value;
+ body = value;
}
if (boost::optional<std::string> value = Lua::getStringField(L, index, "type")) {
@@ -259,21 +262,29 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
}
}
+ if (boost::optional<std::string> 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>();
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;
}