From f140bc1b0be0a31a8280822ca490439d4f103771 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Mon, 6 May 2019 19:48:24 +0000 Subject: Add (R)ecent function to show 10 most recently active threads. --- telem.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/telem.lua b/telem.lua index 8127e48..d2fe594 100755 --- a/telem.lua +++ b/telem.lua @@ -423,6 +423,40 @@ function do_new() print("Post submitted.") end +function do_recent() + local recent = {} + local N = 10 + for i, board in ipairs(boards) do + local threads = get_threads(board) + for _, thread in ipairs(threads) do + local x = {} + x.board = board + x.thread = thread + if #recent < N then + table.insert(recent, x) + table.sort(recent, function(x,y) return x.thread.updated > y.thread.updated end) + elseif thread.updated > recent[N].thread.updated then + table.remove(recent, N) + table.insert(recent, x) + table.sort(recent, function(x,y) return x.thread.updated > y.thread.updated end) + end + end + end + print("Most recently active threads:") + print(colourise("magenta", string.format("%s %s %s", + stringx.ljust("Board name", 20), + stringx.ljust("Thread topic" ,48), + "Latest post")) + ) + print(string.rep("-",79)) + for i, update in ipairs(recent) do + io.write(colourise("cyan", stringx.ljust(update.board.name,20)) .. " " .. + stringx.ljust(update.thread.subject, 48) .. " " .. + os.date("%B %d, %Y", update.thread.updated) .. "\n") + end + print(string.rep("-",79)) +end + function do_scan() for i, board in ipairs(boards) do io.write(string.format("%3d ", i)) @@ -644,6 +678,7 @@ dispatch["="] = do_unimplemented dispatch["M"] = do_unimplemented dispatch["n"] = do_new dispatch["r"] = do_reply +dispatch["R"] = do_recent dispatch["b"] = do_board dispatch["c"] = do_colour -- cgit v1.2.3