diff options
| author | Roger Planas <roger.planas@isode.com> | 2014-07-03 13:09:06 (GMT) |
|---|---|---|
| committer | Swift Review <review@swift.im> | 2014-07-18 14:20:54 (GMT) |
| commit | e3ff5f241bf6e41829d36502e75f585d9620737e (patch) | |
| tree | bff095606e0e18c63f2d2f7b6404de580addd793 /Sluift | |
| parent | 00375bb2ac48dae174889ed9cea8dc8de55e1efd (diff) | |
| download | swift-contrib-e3ff5f241bf6e41829d36502e75f585d9620737e.zip swift-contrib-e3ff5f241bf6e41829d36502e75f585d9620737e.tar.bz2 | |
Sluift: Add 'show' parameter option to send_presence methods
Change-Id: I9fbd4514f6bc0d46738154abce495519e43ad46b
Diffstat (limited to 'Sluift')
| -rw-r--r-- | Sluift/ElementConvertors/StatusShowConvertor.cpp | 63 | ||||
| -rw-r--r-- | Sluift/ElementConvertors/StatusShowConvertor.h | 3 | ||||
| -rw-r--r-- | Sluift/client.cpp | 5 | ||||
| -rw-r--r-- | Sluift/component.cpp | 5 |
4 files changed, 52 insertions, 24 deletions
diff --git a/Sluift/ElementConvertors/StatusShowConvertor.cpp b/Sluift/ElementConvertors/StatusShowConvertor.cpp index c8a5bd6..d8e24ab 100644 --- a/Sluift/ElementConvertors/StatusShowConvertor.cpp +++ b/Sluift/ElementConvertors/StatusShowConvertor.cpp @@ -4,56 +4,71 @@ * See the COPYING file for more information. */ #include <Sluift/ElementConvertors/StatusShowConvertor.h> #include <lua.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <boost/numeric/conversion/cast.hpp> #include <Sluift/Lua/Check.h> +#include <Sluift/Lua/Exception.h> using namespace Swift; StatusShowConvertor::StatusShowConvertor() : GenericLuaElementConvertor<StatusShow>("show") { } StatusShowConvertor::~StatusShowConvertor() { } boost::shared_ptr<StatusShow> StatusShowConvertor::doConvertFromLua(lua_State* L) { boost::shared_ptr<StatusShow> result = boost::make_shared<StatusShow>(); lua_getfield(L, -1, "type"); if (lua_isstring(L, -1)) { - if (std::string(lua_tostring(L, -1)) == "online") { - result->setType(StatusShow::Online); - } - if (std::string(lua_tostring(L, -1)) == "ffc") { - result->setType(StatusShow::FFC); - } - if (std::string(lua_tostring(L, -1)) == "away") { - result->setType(StatusShow::Away); - } - if (std::string(lua_tostring(L, -1)) == "xa") { - result->setType(StatusShow::XA); - } - if (std::string(lua_tostring(L, -1)) == "dnd") { - result->setType(StatusShow::DND); - } + result->setType(convertStatusShowTypeFromString(lua_tostring(L, -1))); } lua_pop(L, 1); return result; } void StatusShowConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<StatusShow> payload) { lua_createtable(L, 0, 0); - if (payload->getType() != StatusShow::None) { - switch (payload->getType()) { - case StatusShow::Online: lua_pushstring(L, "online"); break; - case StatusShow::FFC: lua_pushstring(L, "ffc"); break; - case StatusShow::Away: lua_pushstring(L, "away"); break; - case StatusShow::XA: lua_pushstring(L, "xa"); break; - case StatusShow::DND: lua_pushstring(L, "dnd"); break; - case StatusShow::None: assert(false); break; - } + const std::string show = convertStatusShowTypeToString(payload->getType()); + if (!show.empty()) { + lua_pushstring(L, show.c_str()); lua_setfield(L, -2, "type"); } } + +std::string StatusShowConvertor::convertStatusShowTypeToString(const StatusShow::Type &show) { + switch (show) { + case StatusShow::Online: return "online"; break; + case StatusShow::FFC: return "ffc"; break; + case StatusShow::Away: return "away"; break; + case StatusShow::XA: return "xa"; break; + case StatusShow::DND: return "dnd"; break; + case StatusShow::None: return ""; break; + } + assert(false); + return ""; +} + +StatusShow::Type StatusShowConvertor::convertStatusShowTypeFromString(const std::string& show) { + if (show == "online") { + return StatusShow::Online; + } + else if (show == "ffc") { + return StatusShow::FFC; + } + else if (show == "away") { + return StatusShow::Away; + } + else if (show == "xa") { + return StatusShow::XA; + } + else if (show == "dnd") { + return StatusShow::DND; + } + else { + throw Lua::Exception("Illegal status show: '" + show + "'"); + } +} diff --git a/Sluift/ElementConvertors/StatusShowConvertor.h b/Sluift/ElementConvertors/StatusShowConvertor.h index 32253ec..ef8ed48 100644 --- a/Sluift/ElementConvertors/StatusShowConvertor.h +++ b/Sluift/ElementConvertors/StatusShowConvertor.h @@ -13,11 +13,14 @@ namespace Swift { class StatusShowConvertor : public GenericLuaElementConvertor<StatusShow> { public: StatusShowConvertor(); virtual ~StatusShowConvertor(); virtual boost::shared_ptr<StatusShow> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE; virtual void doConvertToLua(lua_State*, boost::shared_ptr<StatusShow>) SWIFTEN_OVERRIDE; + + static std::string convertStatusShowTypeToString(const StatusShow::Type &show); + static StatusShow::Type convertStatusShowTypeFromString(const std::string& show); }; } diff --git a/Sluift/client.cpp b/Sluift/client.cpp index 4b065ab..e8e6a1a 100644 --- a/Sluift/client.cpp +++ b/Sluift/client.cpp @@ -34,18 +34,19 @@ #include <Sluift/Lua/Check.h> #include <Sluift/Lua/Value.h> #include <Sluift/Lua/Exception.h> #include <Sluift/Lua/LuaUtils.h> #include <Sluift/globals.h> #include <Sluift/ElementConvertors/StanzaConvertor.h> #include <Sluift/ElementConvertors/IQConvertor.h> #include <Sluift/ElementConvertors/PresenceConvertor.h> #include <Sluift/ElementConvertors/MessageConvertor.h> +#include <Sluift/ElementConvertors/StatusShowConvertor.h> using namespace Swift; namespace lambda = boost::lambda; static inline SluiftClient* getClient(lua_State* L) { return *Lua::checkUserData<SluiftClient>(L, 1); } static inline int getGlobalTimeout(lua_State* L) { @@ -276,18 +277,19 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( SLUIFT_LUA_FUNCTION_WITH_HELP( Client, send_presence, "Send presence.", "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" "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" "type the type of message to send (`available`, `error`, `probe`, `subscribe`, `subscribed`, `unavailable`, `unsubscribe`, `unsubscribed`)\n" "payloads payloads to add to the presence\n" ) { Sluift::globals.eventLoop.runOnce(); boost::shared_ptr<Presence> presence = boost::make_shared<Presence>(); int index = 2; if (lua_isstring(L, index)) { @@ -301,18 +303,21 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( if (boost::optional<std::string> value = Lua::getStringField(L, index, "status")) { presence->setStatus(*value); } if (boost::optional<int> value = Lua::getIntField(L, index, "priority")) { presence->setPriority(*value); } if (boost::optional<std::string> value = Lua::getStringField(L, index, "type")) { presence->setType(PresenceConvertor::convertPresenceTypeFromString(*value)); } + if (boost::optional<std::string> value = Lua::getStringField(L, index, "show")) { + presence->setShow(StatusShowConvertor::convertStatusShowTypeFromString(*value)); + } std::vector< boost::shared_ptr<Payload> > payloads = getPayloadsFromTable(L, index); presence->addPayloads(payloads.begin(), payloads.end()); } getClient(L)->getClient()->getPresenceSender()->sendPresence(presence); lua_pushvalue(L, 1); return 0; } diff --git a/Sluift/component.cpp b/Sluift/component.cpp index 0c400b3..6ae78ec 100644 --- a/Sluift/component.cpp +++ b/Sluift/component.cpp @@ -33,18 +33,19 @@ #include <Sluift/Lua/Check.h> #include <Sluift/Lua/Value.h> #include <Sluift/Lua/Exception.h> #include <Sluift/Lua/LuaUtils.h> #include <Sluift/globals.h> #include <Sluift/ElementConvertors/StanzaConvertor.h> #include <Sluift/ElementConvertors/IQConvertor.h> #include <Sluift/ElementConvertors/PresenceConvertor.h> #include <Sluift/ElementConvertors/MessageConvertor.h> +#include <Sluift/ElementConvertors/StatusShowConvertor.h> using namespace Swift; namespace lambda = boost::lambda; static inline SluiftComponent* getComponent(lua_State* L) { return *Lua::checkUserData<SluiftComponent>(L, 1); } static inline int getGlobalTimeout(lua_State* L) { @@ -253,18 +254,19 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( Component, send_presence, "Send presence.", "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" "from the JID to send the message from\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" "type the type of message to send (`available`, `error`, `probe`, `subscribe`, `subscribed`, `unavailable`, `unsubscribe`, `unsubscribed`)\n" "payloads payloads to add to the presence\n" ) { Sluift::globals.eventLoop.runOnce(); boost::shared_ptr<Presence> presence = boost::make_shared<Presence>(); int index = 2; if (lua_isstring(L, index)) { @@ -281,18 +283,21 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( if (boost::optional<std::string> value = Lua::getStringField(L, index, "status")) { presence->setStatus(*value); } if (boost::optional<int> value = Lua::getIntField(L, index, "priority")) { presence->setPriority(*value); } if (boost::optional<std::string> value = Lua::getStringField(L, index, "type")) { presence->setType(PresenceConvertor::convertPresenceTypeFromString(*value)); } + if (boost::optional<std::string> value = Lua::getStringField(L, index, "show")) { + presence->setShow(StatusShowConvertor::convertStatusShowTypeFromString(*value)); + } std::vector< boost::shared_ptr<Payload> > payloads = getPayloadsFromTable(L, index); presence->addPayloads(payloads.begin(), payloads.end()); } getComponent(L)->getComponent()->sendPresence(presence); lua_pushvalue(L, 1); return 0; } |
Swift