Changeset

940:80ede103d7a3

mod_blocking: Fix handling of unblocking command. Send out un-/block pushes to all resources.
author Tobias Markmann <tm@ayena.de>
date Wed, 27 Mar 2013 13:29:38 +0100
parents 939:1415fc2a0ac0
children 941:a6c2345bcf87
files mod_blocking/mod_blocking.lua
diffstat 1 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_blocking/mod_blocking.lua	Mon Mar 25 06:40:05 2013 +0100
+++ b/mod_blocking/mod_blocking.lua	Wed Mar 27 13:29:38 2013 +0100
@@ -100,6 +100,21 @@
 	return jid_list;
 end
 
+local function send_push_iqs(username, host, command_type, jids)
+	local bare_jid = username.."@"..host;
+
+	local stanza_content = st.stanza(command_type, { xmlns = xmlns_blocking });
+	for _, jid in ipairs(jids) do
+		stanza_content:tag("item", { jid = jid }):up();
+	end
+
+	for resource, session in pairs(prosody.bare_sessions[bare_jid].sessions) do
+		local iq_push_stanza = st.iq({ type = "set", to = bare_jid.."/"..resource });
+		iq_push_stanza:add_child(stanza_content);
+		session.send(iq_push_stanza);
+	end
+end
+
 function handle_blocking_command(event)
 	local session, stanza = event.origin, event.stanza;
 
@@ -118,11 +133,24 @@
 					add_blocked_jid(username, host, jid);
 				end
 				session.send(st.reply(stanza));
+				send_push_iqs(username, host, "block", block_jid_list);
 			end
 			return true;
 		elseif stanza.tags[1].name == "unblock" then
-			remove_all_blocked_jids(username, host);
+			local unblock = stanza.tags[1];
+			local unblock_jid_list = {};
+			for item in unblock:childtags() do
+				unblock_jid_list[#unblock_jid_list+1] = item.attr.jid;
+			end
+			if #unblock_jid_list == 0 then
+				remove_all_blocked_jids(username, host);
+			else
+				for _, jid_to_unblock in ipairs(unblock_jid_list) do
+					remove_blocked_jid(username, host, jid_to_unblock);
+				end
+			end
 			session.send(st.reply(stanza));
+			send_push_iqs(username, host, "unblock", unblock_jid_list);
 			return true;
 		end
 	elseif stanza.attr.type == "get" and stanza.tags[1].name == "blocklist" then