# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1521672045 -3600
# Node ID 059183e5571ef1e484eb5739801fd49aee67b6d5
# Parent  6e24a69b03af7730f43bc4375db63ce1758f6b3f
util.pubsub: Allow setting a callback for validating items to be published

diff -r 6e24a69b03af -r 059183e5571e util/pubsub.lua
--- a/util/pubsub.lua	Sun Mar 25 17:02:39 2018 +0200
+++ b/util/pubsub.lua	Wed Mar 21 23:40:45 2018 +0100
@@ -6,6 +6,7 @@
 local default_config = {
 	itemstore = function (config, _) return cache.new(config["max_items"]) end;
 	broadcaster = function () end;
+	itemcheck = function () return true; end;
 	get_affiliation = function () end;
 	capabilities = {};
 };
@@ -306,6 +307,9 @@
 		end
 		node_obj = self.nodes[node];
 	end
+	if not self.config.itemcheck(item) then
+		return nil, "internal-server-error";
+	end
 	local node_data = self.data[node];
 	local ok = node_data:set(id, item);
 	if not ok then