Diff

util/pubsub.lua @ 8376:eb6a9c314c86

util.pubsub: Add method for retreiving the last item (useful for sending on subscribe)
author Kim Alvefur <zash@zash.se>
date Tue, 07 Nov 2017 00:40:52 +0100
parent 8343:5df2f240173b
child 8382:e5d00bf4a4d5
line wrap: on
line diff
--- 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