|
1 local bare_jid = require"util.jid".bare; |
|
2 return function (opts, arg) |
|
3 if opts.short_help then |
|
4 print("Fetch archived messages"); |
|
5 return; |
|
6 end |
|
7 |
|
8 local selfjid; |
|
9 local function print_message(m) |
|
10 -- TODO Roster lookup |
|
11 -- TODO Timestamp |
|
12 local a = m.attr; |
|
13 if bare_jid(a.from) == selfjid then |
|
14 print("To ".. bare_jid(a.to)); |
|
15 else |
|
16 print("From ".. bare_jid(a.from)); |
|
17 end |
|
18 print(m:get_child_text"body"); |
|
19 print""; |
|
20 end |
|
21 |
|
22 print"opts" |
|
23 for k,v in pairs(opts) do |
|
24 print("",k,v) |
|
25 end |
|
26 |
|
27 local function on_connect(conn) |
|
28 if opts.debug then |
|
29 conn:hook("stanza-out", print); |
|
30 conn:hook("stanza", print); |
|
31 end |
|
32 selfjid = bare_jid(conn.jid); |
|
33 local function handle_results(ok, result) |
|
34 for i=1,#result do |
|
35 print_message(result[i].message); |
|
36 end |
|
37 if result.last then |
|
38 io.stderr:write "--More--" |
|
39 if io.read"*l" then |
|
40 opts.after = result.last; |
|
41 conn:query_archive(nil, opts, handle_results); |
|
42 return |
|
43 end |
|
44 end |
|
45 conn:close(); |
|
46 end |
|
47 conn:add_plugin"archive"; |
|
48 -- TODO conn:add_plugin"roster"; |
|
49 -- c.roster:fetch(function() |
|
50 conn:query_archive(nil, opts, handle_results); |
|
51 end |
|
52 clix_connect(opts, on_connect); |
|
53 end |