Diff

plugins/mod_pep.lua @ 6544:2f709bc35575

mod_pep: Fire an event when an item is published
author Kim Alvefur <zash@zash.se>
date Sat, 20 Dec 2014 21:34:59 +0100
parent 5805:11b6157ee274
child 6866:abff7543b79c
line wrap: on
line diff
--- a/plugins/mod_pep.lua	Sat Dec 13 16:40:55 2014 +0100
+++ b/plugins/mod_pep.lua	Sat Dec 20 21:34:59 2014 +0100
@@ -41,7 +41,8 @@
 	return is_contact_subscribed(username, host, recipient_bare);
 end
 
-local function publish(session, node, id, item)
+module:hook("pep-publish-item", function (event)
+	local session, node, id, item = event.session, event.node, event.id, event.item;
 	item.attr.xmlns = nil;
 	local disable = #item.tags ~= 1 or #item.tags[1] == 0;
 	if #item.tags == 0 then item.name = "retract"; end
@@ -72,7 +73,8 @@
 			core_post_stanza(session, stanza);
 		end
 	end
-end
+end);
+
 local function publish_all(user, recipient, session)
 	local d = data[user];
 	local notify = recipients[user] and recipients[user][recipient];
@@ -172,7 +174,9 @@
 				local id = payload.attr.id or "1";
 				payload.attr.id = id;
 				session.send(st.reply(stanza));
-				publish(session, node, id, st.clone(payload));
+				module:fire_event("pep-publish-item", {
+					node = node, actor = session.jid, id = id, session = session, item = st.clone(payload);
+				});
 				return true;
 			end
 		end