clix/archive.lua

Mon, 25 Jun 2012 02:41:02 +0200

author
Kim Alvefur <zash@zash.se>
date
Mon, 25 Jun 2012 02:41:02 +0200
changeset 77
22be057cf590
parent 75
8d5c99f46cb8
child 78
bed3cfce7d60
permissions
-rw-r--r--

clix.archive: Remove some debugging code that slipped in

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

	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

mercurial