# HG changeset patch # User Kim Alvefur # Date 1449364969 -3600 # Node ID f350f840a6f74ddd94e4f76a99799bdac989f614 # Parent 9e926e48cbf9214a855cfbec0a17da1abc9bf2cd mod_blocklist: Restructure how we keep track of where to send unavailable presence diff -r 9e926e48cbf9 -r f350f840a6f7 plugins/mod_blocklist.lua --- a/plugins/mod_blocklist.lua Sun Dec 06 02:19:04 2015 +0100 +++ b/plugins/mod_blocklist.lua Sun Dec 06 02:22:49 2015 +0100 @@ -119,6 +119,13 @@ 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 @@ 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 @@ 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 }));