aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_blocklist.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2015-12-06 02:22:49 +0100
committerKim Alvefur <zash@zash.se>2015-12-06 02:22:49 +0100
commit4fb06ad84f91761e45c87e832a95f2d5c57b2d39 (patch)
tree44931ccab91d45ae9644b5891eb2993b50e2f0a8 /plugins/mod_blocklist.lua
parentb4679e21888856879422f78b57b5740315362d23 (diff)
downloadprosody-4fb06ad84f91761e45c87e832a95f2d5c57b2d39.tar.gz
prosody-4fb06ad84f91761e45c87e832a95f2d5c57b2d39.zip
mod_blocklist: Restructure how we keep track of where to send unavailable presence
Diffstat (limited to 'plugins/mod_blocklist.lua')
-rw-r--r--plugins/mod_blocklist.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/plugins/mod_blocklist.lua b/plugins/mod_blocklist.lua
index d5e263b1..c5d0a6bb 100644
--- a/plugins/mod_blocklist.lua
+++ b/plugins/mod_blocklist.lua
@@ -119,6 +119,13 @@ local function edit_blocklist(event)
local action = stanza.tags[1]; -- "block" or "unblock"
local new = {}; -- JIDs to block depending or unblock on action
+ -- XEP-0191 sayeth:
+ -- > When the user blocks communications with the contact, the user's
+ -- > server MUST send unavailable presence information to the contact (but
+ -- > only if the contact is allowed to receive presence notifications [...]
+ -- So contacts we need to do that for are added to the set below.
+ local send_unavailable = {};
+
for item in action:childtags("item") do
local jid = jid_prep(item.attr.jid);
if not jid then
@@ -126,7 +133,10 @@ local function edit_blocklist(event)
return true;
end
item.attr.jid = jid; -- echo back prepped
- new[jid] = is_contact_subscribed(username, module.host, jid) or false;
+ new[jid] = true;
+ if is_contact_subscribed(username, module.host, jid) then
+ send_unavailable[jid] = true;
+ end
end
local is_blocking = action.name == "block" or nil; -- nil if unblocking
@@ -161,8 +171,8 @@ local function edit_blocklist(event)
end
if is_blocking then
- for jid, in_roster in pairs(new) do
- if not blocklist[jid] and in_roster then
+ for jid in pairs(send_unavailable) do
+ if not blocklist[jid] then
for _, session in pairs(sessions[username].sessions) do
if session.presence then
module:send(st.presence({ type = "unavailable", to = jid, from = session.full_jid }));