diff options
author | Kim Alvefur <zash@zash.se> | 2015-12-06 02:30:21 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2015-12-06 02:30:21 +0100 |
commit | ad2e38c94033d6d820ee6c60b1229987f0e7fd8a (patch) | |
tree | 0cbdf5310cc0b8b02c50ba6f96ce84c53753ee7e /plugins | |
parent | fa1e5fcb0ce9cf99e895f67336972258e6963c03 (diff) | |
download | prosody-ad2e38c94033d6d820ee6c60b1229987f0e7fd8a.tar.gz prosody-ad2e38c94033d6d820ee6c60b1229987f0e7fd8a.zip |
mod_blocklist: When blocking someone who sent a subscription request, forget that request since the user would be unable to deny it while blocked (Fixes #574)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mod_blocklist.lua | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/plugins/mod_blocklist.lua b/plugins/mod_blocklist.lua index c5d0a6bb..d7476cb5 100644 --- a/plugins/mod_blocklist.lua +++ b/plugins/mod_blocklist.lua @@ -10,7 +10,11 @@ -- local user_exists = require"core.usermanager".user_exists; -local is_contact_subscribed = require"core.rostermanager".is_contact_subscribed; +local rostermanager = require"core.rostermanager"; +local is_contact_subscribed = rostermanager.is_contact_subscribed; +local is_contact_pending_in = rostermanager.is_contact_pending_in; +local load_roster = rostermanager.load_roster; +local save_roster = rostermanager.save_roster; local st = require"util.stanza"; local st_error_reply = st.error_reply; local jid_prep = require"util.jid".prep; @@ -126,6 +130,10 @@ local function edit_blocklist(event) -- So contacts we need to do that for are added to the set below. local send_unavailable = {}; + -- Because blocking someone currently also blocks the ability to reject + -- subscription requests, we'll preemptively reject such + local remove_pending = {}; + for item in action:childtags("item") do local jid = jid_prep(item.attr.jid); if not jid then @@ -136,6 +144,8 @@ local function edit_blocklist(event) new[jid] = true; if is_contact_subscribed(username, module.host, jid) then send_unavailable[jid] = true; + elseif is_contact_pending_in(username, module.host, jid) then + remove_pending[jid] = true; end end @@ -180,6 +190,15 @@ local function edit_blocklist(event) end end end + + if next(remove_pending) then + local roster = load_roster(username, module.host); + for jid in pairs(remove_pending) do + roster[false].pending[jid] = nil; + end + save_roster(username, module.host, roster); + -- Not much we can do about save failing here + end end local blocklist_push = st.iq({ type = "set", id = "blocklist-push" }) |