Diff

plugins/pubsub.lua @ 159:88cc513e81c8

plugins.pubsub: Fire pubsub/event on incoming pubsub notifications
author Matthew Wild <mwild1@gmail.com>
date Fri, 03 Dec 2010 04:11:18 +0000
parent 154:a4dc96890729
child 165:8c67ea868c06
line wrap: on
line diff
--- a/plugins/pubsub.lua	Tue Nov 30 13:23:24 2010 +0000
+++ b/plugins/pubsub.lua	Fri Dec 03 04:11:18 2010 +0000
@@ -9,6 +9,21 @@
 
 function verse.plugins.pubsub(stream)
 	stream.pubsub = setmetatable({ stream = stream }, pubsub_mt);
+	stream:hook("message", function (message)
+		for pubsub_event in message:matching_tags("event", xmlns_pubsub_event) do
+			local items = pubsub_event:get_child("items");
+			if items then
+				local node = items.attr.node;
+				for item in items:matching_tags("item") do
+					stream:event("pubsub/event", {
+						from = message.attr.from;
+						node = node;
+						item = item;
+					});
+				end
+			end
+		end
+	end);
 end
 
 function pubsub:subscribe(server, node, jid, callback)