# HG changeset patch # User Kim Alvefur # Date 1535743005 -7200 # Node ID f728c8c42860325dc3360770edec9a017008f6b8 # Parent 42dac034b2e05ceea853f244ebc55a6e3b0fd91b mod_pubsub_text_interface: Add a 'last' command for sending the last item diff -r 42dac034b2e0 -r f728c8c42860 mod_pubsub_text_interface/mod_pubsub_text_interface.lua --- a/mod_pubsub_text_interface/mod_pubsub_text_interface.lua Wed Aug 29 23:58:14 2018 +0200 +++ b/mod_pubsub_text_interface/mod_pubsub_text_interface.lua Fri Aug 31 21:16:45 2018 +0200 @@ -13,6 +13,7 @@ - `list` - list available nodes - `subscribe node` - subscribe to a node - `unsubscribe node` - unsubscribe from a node +- `last node` - send the last item (again) ]]; module:hook("message/host", function (event) @@ -47,6 +48,18 @@ elseif command == "unsubscribe" then local ok, err = pubsub:remove_subscription(node_arg, from, jid.bare(from)); reply:body(ok and "OK" or err); + elseif command == "last" then + local ok, item_id, item = pubsub:get_last_item(node_arg, from); + if not ok then + reply:body(item_id); -- err message + elseif not item_id then + reply:body("node is empty"); + else + pubsub.config.broadcaster("items", node_arg, { + [from] = { ["pubsub#include_body"] = true } + }, item); + reply:body("OK"); + end else reply:body("Unknown command. `help` to list commands."); end