diff options
Diffstat (limited to 'Sluift/component.cpp')
| -rw-r--r-- | Sluift/component.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Sluift/component.cpp b/Sluift/component.cpp index 0c400b3..6ae78ec 100644 --- a/Sluift/component.cpp +++ b/Sluift/component.cpp @@ -7,70 +7,71 @@ #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> #include <boost/assign/list_of.hpp> #include <iostream> #include <Sluift/SluiftComponent.h> #include <Swiften/JID/JID.h> #include <Swiften/Elements/SoftwareVersion.h> #include <Swiften/Elements/Message.h> #include <Swiften/Elements/Presence.h> #include <Swiften/Elements/RawXMLPayload.h> #include <Swiften/Elements/RosterItemPayload.h> #include <Swiften/Elements/RosterPayload.h> #include <Swiften/Elements/DiscoInfo.h> #include <Swiften/Elements/MAMQuery.h> #include <Swiften/Queries/GenericRequest.h> #include <Swiften/Presence/PresenceSender.h> #include <Swiften/Roster/XMPPRoster.h> #include <Swiften/Roster/SetRosterRequest.h> #include <Swiften/Presence/SubscriptionManager.h> #include <Swiften/Roster/XMPPRosterItem.h> #include <Swiften/Queries/IQRouter.h> #include <Swiften/Queries/Requests/GetSoftwareVersionRequest.h> #include <Sluift/Lua/FunctionRegistration.h> #include <Swiften/Base/foreach.h> #include <Swiften/Base/IDGenerator.h> #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) { lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.moduleLibIndex); lua_getfield(L, -1, "timeout"); int result = boost::numeric_cast<int>(lua_tointeger(L, -1)); lua_pop(L, 2); return result; } static void addPayloadsToTable(lua_State* L, const std::vector<boost::shared_ptr<Payload> >& payloads) { if (!payloads.empty()) { lua_createtable(L, boost::numeric_cast<int>(payloads.size()), 0); for (size_t i = 0; i < payloads.size(); ++i) { Sluift::globals.elementConvertor.convertToLua(L, payloads[i]); lua_rawseti(L, -2, boost::numeric_cast<int>(i+1)); } Lua::registerGetByTypeIndex(L, -1); lua_setfield(L, -2, "payloads"); } } static boost::shared_ptr<Payload> getPayload(lua_State* L, int index) { if (lua_type(L, index) == LUA_TTABLE) { return boost::dynamic_pointer_cast<Payload>(Sluift::globals.elementConvertor.convertFromLua(L, index)); } else if (lua_type(L, index) == LUA_TSTRING) { return boost::make_shared<RawXMLPayload>(Lua::checkString(L, index)); } @@ -227,98 +228,102 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( } if (!to.isValid()) { throw Lua::Exception("Missing 'to'"); } 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); if (from && !from->empty()) { message->setFrom(*from); } if (body && !body->empty()) { message->setBody(*body); } if (subject) { message->setSubject(*subject); } message->addPayloads(payloads.begin(), payloads.end()); message->setType(type); getComponent(L)->getComponent()->sendMessage(message); return 0; } 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)) { presence->setStatus(lua_tostring(L, index)); ++index; } if (lua_istable(L, index)) { if (boost::optional<std::string> value = Lua::getStringField(L, index, "to")) { presence->setTo(*value); } if (boost::optional<std::string> value = Lua::getStringField(L, index, "from")) { presence->setFrom(*value); } 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; } static int sendQuery(lua_State* L, IQ::Type type) { SluiftComponent* component = getComponent(L); JID to; if (boost::optional<std::string> toString = Lua::getStringField(L, 2, "to")) { to = JID(*toString); } JID from; if (boost::optional<std::string> fromString = Lua::getStringField(L, 2, "from")) { from = JID(*fromString); } int timeout = getGlobalTimeout(L); if (boost::optional<int> timeoutInt = Lua::getIntField(L, 2, "timeout")) { timeout = *timeoutInt; } boost::shared_ptr<Payload> payload; lua_getfield(L, 2, "query"); payload = getPayload(L, -1); lua_pop(L, 1); return component->sendRequest( boost::make_shared< GenericRequest<Payload> >(type, from, to, payload, component->getComponent()->getIQRouter()), timeout).convertToLuaResult(L); } |
Swift