util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
authorKim Alvefur <zash@zash.se>
Tue, 07 Nov 2017 00:40:52 +0100
changeset 8379 eb6a9c314c86
parent 8378 e2037634cdd9
child 8380 58cdbbe3b86a
util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
util/pubsub.lua
--- a/util/pubsub.lua	Tue Nov 07 00:39:35 2017 +0100
+++ b/util/pubsub.lua	Tue Nov 07 00:40:52 2017 +0100
@@ -351,6 +351,15 @@
 	end
 end
 
+function service:get_last_item(node, actor)
+	-- Access checking
+	if not self:may(node, actor, "get_items") then
+		return false, "forbidden";
+	end
+	--
+	return true, self.data[node]:tail();
+end
+
 function service:get_nodes(actor)
 	-- Access checking
 	if not self:may(nil, actor, "get_nodes") then