Software /
code /
clix
Changeset
75:8d5c99f46cb8
clix.archive: New plugin, a MAM browser
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 25 Jun 2012 02:39:41 +0200 |
parents | 74:4b64a556a2cd |
children | 76:aa672fc46be1 |
files | clix/archive.lua |
diffstat | 1 files changed, 53 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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