aboutsummaryrefslogtreecommitdiff
path: root/telem.lua
diff options
context:
space:
mode:
authorSolderpunk <solderpunk@sdf.org>2019-05-06 19:48:24 +0000
committerSolderpunk <solderpunk@sdf.org>2019-05-06 19:48:24 +0000
commitf140bc1b0be0a31a8280822ca490439d4f103771 (patch)
tree935ce57435cc362291f46cbfaaf25924f558468c /telem.lua
parentadd possibility to revert message sort order (diff)
Add (R)ecent function to show 10 most recently active threads.
Diffstat (limited to '')
-rwxr-xr-xtelem.lua35
1 files changed, 35 insertions, 0 deletions
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