Mon, 21 Mar 2016 16:13:02 +0100
clix.adhoc: Print field labels if available
local bare_jid = require"util.jid".bare; local parse_datetime = require"util.datetime".parse; return function (opts, arg) if opts.short_help then print("Fetch archived messages"); return; end local reverse = opts.before; if opts.start then opts.start = parse_datetime(opts.start); end if opts["end"] then opts["end"] = parse_datetime(opts["end"]); end local selfjid; local function print_message(i) -- TODO Roster lookup local m = i.message; local a = m.attr; if i.stamp then print(os.date("%Y-%m-%d %H:%M:%S", i.stamp)); end if a.to and bare_jid(a.to) ~= selfjid then print("To ".. bare_jid(a.to)); end if a.from and bare_jid(a.from) ~= selfjid then print("From ".. bare_jid(a.from)); end print(m:get_child_text"body"); print""; 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]); end if result[reverse and "first" or "last"] then local fetch_next = opts.everything; if opts.interactive and not fetch_next then io.stderr:write "--More--" fetch_next = io.read"*l" or print(); end if fetch_next then if reverse then opts.before = result.first and result.first[1]; else opts.after = result.last; end conn:query_archive(opts.to, opts, handle_results); return else local whatnext, nextpage = reverse and "before" or "after"; if reverse then nextpage = result.first and result.first[1]; else nextpage = result.last; end conn:info("Next page: --%s=%s", whatnext, nextpage); end end if result.count then conn:info("Total: %d items", result.count); end conn:close(); end conn:add_plugin"archive"; -- TODO conn:add_plugin"roster"; -- c.roster:fetch(function() conn:query_archive(opts.to, opts, handle_results); end clix_connect(opts, on_connect); end