Changeset

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
parents 158:068176069dfa
children 160:5cbbfe42212e
files plugins/pubsub.lua
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
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)