# HG changeset patch # User Kim Alvefur # Date 1340584781 -7200 # Node ID 8d5c99f46cb8820cbf48f22b4e87bd3a21466636 # Parent 4b64a556a2cd4cdb279e02491bb7d5805555435c clix.archive: New plugin, a MAM browser diff -r 4b64a556a2cd -r 8d5c99f46cb8 clix/archive.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clix/archive.lua Mon Jun 25 02:39:41 2012 +0200 @@ -0,0 +1,53 @@ +local bare_jid = require"util.jid".bare; +return function (opts, arg) + if opts.short_help then + print("Fetch archived messages"); + return; + end + + local selfjid; + local function print_message(m) + -- TODO Roster lookup + -- TODO Timestamp + local a = m.attr; + if bare_jid(a.from) == selfjid then + print("To ".. bare_jid(a.to)); + else + print("From ".. bare_jid(a.from)); + end + print(m:get_child_text"body"); + print""; + end + + print"opts" + for k,v in pairs(opts) do + print("",k,v) + end + + local function on_connect(conn) + if opts.debug then + conn:hook("stanza-out", print); + conn:hook("stanza", print); + end + selfjid = bare_jid(conn.jid); + local function handle_results(ok, result) + for i=1,#result do + print_message(result[i].message); + end + if result.last then + io.stderr:write "--More--" + if io.read"*l" then + opts.after = result.last; + conn:query_archive(nil, opts, handle_results); + return + end + end + conn:close(); + end + conn:add_plugin"archive"; + -- TODO conn:add_plugin"roster"; + -- c.roster:fetch(function() + conn:query_archive(nil, opts, handle_results); + end + clix_connect(opts, on_connect); +end