changeset 3293:f728c8c42860

mod_pubsub_text_interface: Add a 'last' command for sending the last item
author Kim Alvefur <zash@zash.se>
date Fri, 31 Aug 2018 21:16:45 +0200
parents 42dac034b2e0
children 947790ec4406
files mod_pubsub_text_interface/mod_pubsub_text_interface.lua
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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