From 256d1392b0d45ffeac44f764297ea31d65cb0229 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Fri, 25 Jan 2019 14:40:19 +0000
Subject: Allow Sluift to set stanza IDs

Test-Information:
Compiles

Change-Id: I5bfbf270524a1a31c9105f108f47f64eb95276d1

diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index 24ece85..814ad45 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -299,6 +299,7 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
         "body  the body of the message. Can alternatively be specified using the `body` option\n",
 
         "to  the JID to send the message to\n"
+        "id  the id to set on the stanza\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"
@@ -307,6 +308,7 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
     Sluift::globals.eventLoop.runOnce();
     JID to;
     boost::optional<std::string> body;
+    boost::optional<std::string> id;
     boost::optional<std::string> subject;
     std::vector<std::shared_ptr<Payload> > payloads;
     int index = 2;
@@ -324,6 +326,10 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
             to = *value;
         }
 
+        if (boost::optional<std::string> value = Lua::getStringField(L, index, "id")) {
+            id = value;
+        }
+
         if (boost::optional<std::string> value = Lua::getStringField(L, index, "body")) {
             body = value;
         }
@@ -350,6 +356,9 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
     if (body && !body->empty()) {
         message->setBody(*body);
     }
+    if (id) {
+        message->setID(*id);
+    }
     if (subject) {
         message->setSubject(*subject);
     }
@@ -369,7 +378,8 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
         "self\n"
         "body  the text of the presence. Can alternatively be specified using the `status` option\n",
 
-        "to  the JID to send the message to\n"
+        "to  the JID to send the presence to\n"
+        "id  the id to set on the stanza\n"
         "status  the text of the presence\n"
         "show  the availability of the presence (`online`, `ffc`, `away`, `xa`, `dnd`)\n"
         "priority  the priority of the presence\n"
@@ -388,6 +398,9 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
         if (boost::optional<std::string> value = Lua::getStringField(L, index, "to")) {
             presence->setTo(*value);
         }
+        if (boost::optional<std::string> id = Lua::getStringField(L, index, "id")) {
+            presence->setID(*id);
+        }
         if (boost::optional<std::string> value = Lua::getStringField(L, index, "status")) {
             presence->setStatus(*value);
         }
-- 
cgit v0.10.2-6-g49f6