Changeset

216:3aac084855e6

plugins.pep: Reuse the pubsub plugin.
author Kim Alvefur <zash@zash.se>
date Thu, 08 Sep 2011 18:03:07 +0200
parents 215:f86e0b0a0be3
children 217:60db4e738910
files plugins/pep.lua
diffstat 1 files changed, 4 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/pep.lua	Thu Sep 08 17:51:11 2011 +0200
+++ b/plugins/pep.lua	Thu Sep 08 18:03:07 2011 +0200
@@ -3,22 +3,11 @@
 local xmlns_pubsub_event = xmlns_pubsub.."#event";
 
 function verse.plugins.pep(stream)
+	stream:add_plugin("pubsub");
 	stream.pep = {};
 	
-	stream:hook("message", function (message)
-		local event = message:get_child("event", xmlns_pubsub_event);
-		if not event then return; end
-		local items = event:get_child("items");
-		if not items then return; end
-		local node = items.attr.node;
-		for item in items:childtags() do
-			if item.name == "item" and item.attr.xmlns == xmlns_pubsub_event then
-				stream:event("pep/"..node, {
-					from = message.attr.from,
-					item = item.tags[1],
-				});
-			end
-		end
+	stream:hook("pubsub/event", function(event)
+		return stream:event("pep/"..event.node, { from = event.from, item = event.item[1] } );
 	end);
 	
 	function stream:hook_pep(node, callback, priority)
@@ -38,11 +27,6 @@
 	end
 	
 	function stream:publish_pep(item, node)
-		local publish = verse.iq({ type = "set" })
-			:tag("pubsub", { xmlns = xmlns_pubsub })
-				:tag("publish", { node = node or item.attr.xmlns })
-					:tag("item")
-						:add_child(item);
-		return stream:send_iq(publish);
+		return stream.pubsub:publish(nil, node or item.attr.xmlns, nil, item)
 	end
 end