Diff

plugins/mod_pep.lua @ 1401:a3ce55c1e43a

mod_pep: Remove data when a user disables a node
author Waqas Hussain <waqas20@gmail.com>
date Wed, 24 Jun 2009 19:38:28 +0500
parent 1400:cbbb4f4fed68
child 1402:34723bbd5acb
line wrap: on
line diff
--- a/plugins/mod_pep.lua	Wed Jun 24 19:28:48 2009 +0500
+++ b/plugins/mod_pep.lua	Wed Jun 24 19:38:28 2009 +0500
@@ -6,6 +6,7 @@
 local user_exists = require "core.usermanager".user_exists;
 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
 local pairs, ipairs = pairs, ipairs;
+local next = next;
 local load_roster = require "core.rostermanager".load_roster;
 
 local data = {};
@@ -15,6 +16,7 @@
 module:add_feature("http://jabber.org/protocol/pubsub#publish");
 
 local function publish(session, node, item)
+	local disable = #item.tags ~= 1 or #item.tags[1].tags == 0;
 	local stanza = st.message({from=session.full_jid, type='headline'})
 		:tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'})
 			:tag('items', {node=node})
@@ -25,8 +27,13 @@
 	local bare = session.username..'@'..session.host;
 	-- store for the future
 	local user_data = data[bare];
-	if not user_data then user_data = {}; data[bare] = user_data; end
-	user_data[node] = stanza;
+	if disable then
+		if user_data then user_data[node] = nil; end
+		if not next(user_data) then data[bare] = nil; end
+	else
+		if not user_data then user_data = {}; data[bare] = user_data; end
+		user_data[node] = stanza;
+	end
 	
 	-- broadcast to resources
 	stanza.attr.to = bare;