diff options
author | Edwin Mons <edwin.mons@isode.com> | 2014-09-10 13:46:49 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2014-09-16 14:36:20 (GMT) |
commit | fc2714bf30ddd447405082ba4f8fa93bda369a6f (patch) | |
tree | d0018535348ffd17d21563833d8295da0d316ec6 | |
parent | dc48cc3f34e3e229172202717520e77233c37ed7 (diff) | |
download | swift-contrib-fc2714bf30ddd447405082ba4f8fa93bda369a6f.zip swift-contrib-fc2714bf30ddd447405082ba4f8fa93bda369a6f.tar.bz2 |
Add Subject element convertor to Sluift
Test Information:
MAM queries now return a payload of _type='subject'.
Change-Id: I4fe4eb5105f4f19d146e4cca741d35bb7760cf6c
-rw-r--r-- | Sluift/ElementConvertors/SConscript | 3 | ||||
-rw-r--r-- | Sluift/ElementConvertors/SubjectConvertor.cpp | 35 | ||||
-rw-r--r-- | Sluift/ElementConvertors/SubjectConvertor.h | 25 | ||||
-rw-r--r-- | Sluift/LuaElementConvertors.cpp | 2 |
4 files changed, 64 insertions, 1 deletions
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>()); |