plugins/pep.lua

Thu, 24 Nov 2011 06:23:43 +0100

author
Kim Alvefur <zash@zash.se>
date
Thu, 24 Nov 2011 06:23:43 +0100
changeset 232
5b49de3aa0f3
parent 216
3aac084855e6
child 249
00891a675634
permissions
-rw-r--r--

plugins.pep: Set item to the first tag instead of first child.


local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
local xmlns_pubsub_event = xmlns_pubsub.."#event";

function verse.plugins.pep(stream)
	stream:add_plugin("pubsub");
	stream.pep = {};
	
	stream:hook("pubsub/event", function(event)
		return stream:event("pep/"..event.node, { from = event.from, item = event.item.tags[1] } );
	end);
	
	function stream:hook_pep(node, callback, priority)
		local handlers = stream.events._handlers["pep/"..node];
		if not(handlers) or #handlers == 0 then
			stream:add_disco_feature(node.."+notify");
		end
		stream:hook("pep/"..node, callback, priority);
	end
	
	function stream:unhook_pep(node, callback)
		stream:unhook("pep/"..node, callback);
		local handlers = stream.events._handlers["pep/"..node];
		if not(handlers) or #handlers == 0 then
			stream:remove_disco_feature(node.."+notify");
		end
	end
	
	function stream:publish_pep(item, node)
		return stream.pubsub:publish(nil, node or item.attr.xmlns, nil, item)
	end
end

mercurial