From fc2714bf30ddd447405082ba4f8fa93bda369a6f Mon Sep 17 00:00:00 2001
From: Edwin Mons <edwin.mons@isode.com>
Date: Wed, 10 Sep 2014 15:46:49 +0200
Subject: Add Subject element convertor to Sluift

Test Information:

MAM queries now return a payload of _type='subject'.

Change-Id: I4fe4eb5105f4f19d146e4cca741d35bb7760cf6c

diff --git a/Sluift/ElementConvertors/SConscript b/Sluift/ElementConvertors/SConscript
index 7317ac7..b9bfc22 100644
--- a/Sluift/ElementConvertors/SConscript
+++ b/Sluift/ElementConvertors/SConscript
@@ -47,6 +47,7 @@ convertors = [
 	env.File("ForwardedConvertor.cpp"),
 	env.File("MAMResultConvertor.cpp"),
 	env.File("MAMQueryConvertor.cpp"),
-	env.File("MAMArchivedConvertor.cpp")
+	env.File("MAMArchivedConvertor.cpp"),
+	env.File("SubjectConvertor.cpp")
 ]
 Return('convertors')
diff --git a/Sluift/ElementConvertors/SubjectConvertor.cpp b/Sluift/ElementConvertors/SubjectConvertor.cpp
new file mode 100644
index 0000000..29e2c4f
--- /dev/null
+++ b/Sluift/ElementConvertors/SubjectConvertor.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Sluift/ElementConvertors/SubjectConvertor.h>
+
+#include <lua.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <Sluift/Lua/LuaUtils.h>
+
+using namespace Swift;
+
+SubjectConvertor::SubjectConvertor() : GenericLuaElementConvertor<Subject>("subject") {
+}
+
+SubjectConvertor::~SubjectConvertor() {
+}
+
+boost::shared_ptr<Subject> SubjectConvertor::doConvertFromLua(lua_State* L) {
+	boost::shared_ptr<Subject> result = boost::make_shared<Subject>();
+	if (boost::optional<std::string> value = Lua::getStringField(L, -1, "text")) {
+		result->setText(*value);
+	}
+	return result;
+}
+
+void SubjectConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<Subject> payload) {
+	lua_createtable(L, 0, 0);
+	if (!payload->getText().empty()) {
+		lua_pushstring(L, payload->getText().c_str());
+		lua_setfield(L, -2, "text");
+	}
+}
diff --git a/Sluift/ElementConvertors/SubjectConvertor.h b/Sluift/ElementConvertors/SubjectConvertor.h
new file mode 100644
index 0000000..4b3716e
--- /dev/null
+++ b/Sluift/ElementConvertors/SubjectConvertor.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/Override.h>
+
+#include <Sluift/GenericLuaElementConvertor.h>
+#include <Swiften/Elements/Subject.h>
+
+namespace Swift {
+	class LuaElementConvertors;
+
+	class SubjectConvertor : public GenericLuaElementConvertor<Subject> {
+		public:
+			SubjectConvertor();
+			virtual ~SubjectConvertor();
+
+			virtual boost::shared_ptr<Subject> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
+			virtual void doConvertToLua(lua_State*, boost::shared_ptr<Subject>) SWIFTEN_OVERRIDE;
+	};
+}
diff --git a/Sluift/LuaElementConvertors.cpp b/Sluift/LuaElementConvertors.cpp
index 9ca932e..253a820 100644
--- a/Sluift/LuaElementConvertors.cpp
+++ b/Sluift/LuaElementConvertors.cpp
@@ -21,6 +21,7 @@
 #include <Sluift/ElementConvertors/VCardUpdateConvertor.h>
 #include <Sluift/ElementConvertors/VCardConvertor.h>
 #include <Sluift/ElementConvertors/BodyConvertor.h>
+#include <Sluift/ElementConvertors/SubjectConvertor.h>
 #include <Sluift/ElementConvertors/CommandConvertor.h>
 #include <Sluift/ElementConvertors/StatusShowConvertor.h>
 #include <Sluift/ElementConvertors/StatusConvertor.h>
@@ -46,6 +47,7 @@ LuaElementConvertors::LuaElementConvertors() {
 	convertors.push_back(boost::make_shared<CommandConvertor>(this));
 	convertors.push_back(boost::make_shared<PubSubEventConvertor>(this));
 	convertors.push_back(boost::make_shared<BodyConvertor>());
+	convertors.push_back(boost::make_shared<SubjectConvertor>());
 	convertors.push_back(boost::make_shared<VCardConvertor>());
 	convertors.push_back(boost::make_shared<VCardUpdateConvertor>());
 	convertors.push_back(boost::make_shared<FormConvertor>());
-- 
cgit v0.10.2-6-g49f6