diff options
author | Richard Maudsley <richard.maudsley@isode.com> | 2014-05-13 14:48:10 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2014-05-27 19:53:49 (GMT) |
commit | 058719296f496b14b906fdee3d74d72a78d9f6a2 (patch) | |
tree | e15b5e0032b48c924f7f69e20e0b721172a5691d | |
parent | e5975a6d4809bf05f8c9df724c926bd26fc4a9df (diff) | |
download | swift-contrib-058719296f496b14b906fdee3d74d72a78d9f6a2.zip swift-contrib-058719296f496b14b906fdee3d74d72a78d9f6a2.tar.bz2 |
Added Sluift MAM examples. send_mam_query becomes set_mam_query.
Change-Id: I5d81e2476c83a16a8e478656d11d91137b009f3a
-rw-r--r-- | Sluift/ElementConvertors/MAMQueryConvertor.cpp | 2 | ||||
-rw-r--r-- | Sluift/Examples/MAMRSM.lua | 23 | ||||
-rw-r--r-- | Sluift/Examples/MAMRSMPage.lua | 36 | ||||
-rw-r--r-- | Sluift/Examples/MAMSimple.lua | 19 | ||||
-rw-r--r-- | Sluift/Examples/MAMSupportedFields.lua | 18 | ||||
-rw-r--r-- | Sluift/Examples/MAMUser.lua | 25 | ||||
-rw-r--r-- | Sluift/client.cpp | 29 | ||||
-rw-r--r-- | Sluift/core.lua | 6 |
8 files changed, 126 insertions, 32 deletions
diff --git a/Sluift/ElementConvertors/MAMQueryConvertor.cpp b/Sluift/ElementConvertors/MAMQueryConvertor.cpp index 7d7224e..cf4f787 100644 --- a/Sluift/ElementConvertors/MAMQueryConvertor.cpp +++ b/Sluift/ElementConvertors/MAMQueryConvertor.cpp @@ -17,7 +17,7 @@ using namespace Swift; MAMQueryConvertor::MAMQueryConvertor(LuaElementConvertors* convertors) : - GenericLuaElementConvertor<MAMQuery>("mam_query"), + GenericLuaElementConvertor<MAMQuery>("mam"), convertors(convertors) { } diff --git a/Sluift/Examples/MAMRSM.lua b/Sluift/Examples/MAMRSM.lua new file mode 100644 index 0000000..c8a1e85 --- /dev/null +++ b/Sluift/Examples/MAMRSM.lua @@ -0,0 +1,23 @@ +-- A query using Result Set Management +-- Usage: ./sluift MAMRSM.lua <jid> <password> <query_dest> <max_results> + +sluift.debug = true + +c = sluift.new_client(arg[1], arg[2]) + +c:connect(); + +query = { + result_set={max_items=arg[4]} +} + +c:set_mam{mam=query, to=arg[3]} + +c:for_each_message(function(e) + if e.payloads[1].tag == 'fin' then return true end + if e.payloads[1]._type == 'mam_result' then + print(e.payloads[1].payload.stanza.payloads[1].text) + end +end) + +c:disconnect() diff --git a/Sluift/Examples/MAMRSMPage.lua b/Sluift/Examples/MAMRSMPage.lua new file mode 100644 index 0000000..cb3307c --- /dev/null +++ b/Sluift/Examples/MAMRSMPage.lua @@ -0,0 +1,36 @@ +-- A page query using Result Set Management +-- Usage: ./sluift MAMRSMPage.lua <jid> <password> <query_dest> <pages> + +sluift.debug = true + +c = sluift.new_client(arg[1], arg[2]) + +c:set_options{compress = false, tls = false} + +c:connect(); + +query = { + result_set={max_items=5} +} + +done = false +page = 0 +while not done and page < tonumber(arg[4]) do + page = page + 1 + c:set_mam{mam=query, to=arg[3]} + c:for_each_message(function(e) + if e.payloads[1].tag == 'fin' then + if e.payloads[2].last_id then + query.result_set.after = e.payloads[2].last_id + else + done = true + end + return true + end + if e.payloads[1]._type == 'mam_result' then + print(e.payloads[1].payload.stanza.payloads[1].text) + end + end) +end + +c:disconnect() diff --git a/Sluift/Examples/MAMSimple.lua b/Sluift/Examples/MAMSimple.lua new file mode 100644 index 0000000..13ab1a0 --- /dev/null +++ b/Sluift/Examples/MAMSimple.lua @@ -0,0 +1,19 @@ +-- Querying the archive for messages +-- Usage: ./sluift MAMSimple.lua <jid> <password> <query_dest> + +sluift.debug = true + +c = sluift.new_client(arg[1], arg[2]) + +c:connect(); + +c:set_mam{mam={}, to=arg[3]} + +c:for_each_message(function(e) + if e.payloads[1].tag == 'fin' then return true end + if e.payloads[1]._type == 'mam_result' then + print(e.payloads[1].payload.stanza.payloads[1].text) + end +end) + +c:disconnect() diff --git a/Sluift/Examples/MAMSupportedFields.lua b/Sluift/Examples/MAMSupportedFields.lua new file mode 100644 index 0000000..0417924 --- /dev/null +++ b/Sluift/Examples/MAMSupportedFields.lua @@ -0,0 +1,18 @@ +-- Retrieving form fields +-- Usage: ./sluift MAMSupportedFields.lua <jid> <password> + +sluift.debug = true + +c = sluift.new_client(arg[1], arg[2]) + +c:connect(); + +mam_result = c:get_mam{} + +for i=1,#mam_result.form.fields do + if mam_result.form.fields[i].type ~= "hidden" then + print("Server supports: " .. mam_result.form.fields[i].name) + end +end + +c:disconnect() diff --git a/Sluift/Examples/MAMUser.lua b/Sluift/Examples/MAMUser.lua new file mode 100644 index 0000000..e4a7c28 --- /dev/null +++ b/Sluift/Examples/MAMUser.lua @@ -0,0 +1,25 @@ +-- Querying for all messages to/from a particular JID +-- Usage: ./sluift MAMUser.lua <jid> <password> <query_dest> <query_jid> + +sluift.debug = true + +c = sluift.new_client(arg[1], arg[2]) + +c:connect(); + +fields = { + with = arg[4] +} + +query_form = sluift.create_form{fields, form_type="urn:xmpp:mam:0"} + +c:set_mam{mam={form=query_form}, to=arg[3]} + +c:for_each_message(function(e) + if e.payloads[1].tag == 'fin' then return true end + if e.payloads[1]._type == 'mam_result' then + print(e.payloads[1].payload.stanza.payloads[1].text) + end +end) + +c:disconnect() diff --git a/Sluift/client.cpp b/Sluift/client.cpp index 8dcd9ae..4b065ab 100644 --- a/Sluift/client.cpp +++ b/Sluift/client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Remko Tronçon + * Copyright (c) 2013-2014 Remko Tronçon * Licensed under the GNU General Public License. * See the COPYING file for more information. */ @@ -452,33 +452,6 @@ SLUIFT_LUA_FUNCTION_WITH_HELP( return 0; } -SLUIFT_LUA_FUNCTION_WITH_HELP( - Client, send_mam_query, - - "Builds and sends a MAM query.\n", - - "self\n" - "mam_query parameters for the query\n" - "jid optional jid to set in the 'to' field of the IQ stanza", - - "See help('MAMQuery') for details." -) { - Lua::checkType(L, 2, LUA_TTABLE); - boost::shared_ptr<MAMQuery> mamQuery = boost::make_shared<MAMQuery>(); - lua_getfield(L, 2, "mam_query"); - if (lua_istable(L, -1)) { - mamQuery = boost::dynamic_pointer_cast<MAMQuery>(Sluift::globals.elementConvertor.convertFromLuaUntyped(L, -1, "mam_query")); - } - JID jid; - lua_getfield(L, 2, "jid"); - if (!lua_isnil(L, -1)) { - jid = JID(lua_tostring(L, -1)); - } - IQRouter *router = getClient(L)->getClient()->getIQRouter(); - router->sendIQ(IQ::createRequest(IQ::Set, jid, IDGenerator().generateID(), mamQuery)); - return 0; -} - static void pushEvent(lua_State* L, const SluiftClient::Event& event) { switch (event.type) { case SluiftClient::Event::MessageType: { diff --git a/Sluift/core.lua b/Sluift/core.lua index dfac21a..7487de1 100644 --- a/Sluift/core.lua +++ b/Sluift/core.lua @@ -1,5 +1,5 @@ --[[ - Copyright (c) 2013 Remko Tronçon + Copyright (c) 2013-2014 Remko Tronçon Licensed under the GNU General Public License. See the COPYING file for more information. --]] @@ -747,8 +747,8 @@ register_help(Client.process_events) -- client:set_command{to = 'alice@wonderland.lit', command = { type = 'execute', node = 'uptime' }} -- local get_set_shortcuts = { - get = {'software_version', 'disco_items', 'xml', 'dom', 'vcard'}, - set = {'command'} + get = {'software_version', 'disco_items', 'xml', 'dom', 'vcard', 'mam'}, + set = {'command', 'mam'} } for query_action, query_types in pairs(get_set_shortcuts) do for _, query_type in ipairs(query_types) do |