Software /
code /
prosody
Comparison
plugins/mod_blocklist.lua @ 6352:b703e6930e4c
mod_blocklist: Use full word as variable name, we can afford that
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 12 Aug 2014 15:42:20 +0200 |
parent | 6351:10dc228a45a4 |
child | 6460:6d3187f24608 |
comparison
equal
deleted
inserted
replaced
6351:10dc228a45a4 | 6352:b703e6930e4c |
---|---|
101 -- Add or remove some jid(s) from the blocklist | 101 -- Add or remove some jid(s) from the blocklist |
102 -- We want this to be atomic and not do a partial update | 102 -- We want this to be atomic and not do a partial update |
103 local function edit_blocklist(event) | 103 local function edit_blocklist(event) |
104 local origin, stanza = event.origin, event.stanza; | 104 local origin, stanza = event.origin, event.stanza; |
105 local username = origin.username; | 105 local username = origin.username; |
106 local act = stanza.tags[1]; | 106 local action = stanza.tags[1]; |
107 local new = {}; | 107 local new = {}; |
108 | 108 |
109 local jid; | 109 local jid; |
110 for item in act:childtags("item") do | 110 for item in action:childtags("item") do |
111 jid = jid_prep(item.attr.jid); | 111 jid = jid_prep(item.attr.jid); |
112 if not jid then | 112 if not jid then |
113 return origin.send(st_error_reply(stanza, "modify", "jid-malformed")); | 113 return origin.send(st_error_reply(stanza, "modify", "jid-malformed")); |
114 end | 114 end |
115 item.attr.jid = jid; -- echo back prepped | 115 item.attr.jid = jid; -- echo back prepped |
116 new[jid] = is_contact_subscribed(username, host, jid) or false; | 116 new[jid] = is_contact_subscribed(username, host, jid) or false; |
117 end | 117 end |
118 | 118 |
119 local mode = act.name == "block" or nil; | 119 local mode = action.name == "block" or nil; |
120 | 120 |
121 if mode and not next(new) then | 121 if mode and not next(new) then |
122 -- <block/> element does not contain at least one <item/> child element | 122 -- <block/> element does not contain at least one <item/> child element |
123 return origin.send(st_error_reply(stanza, "modify", "bad-request")); | 123 return origin.send(st_error_reply(stanza, "modify", "bad-request")); |
124 end | 124 end |
154 end | 154 end |
155 end | 155 end |
156 end | 156 end |
157 if sessions[username] then | 157 if sessions[username] then |
158 local blocklist_push = st.iq({ type = "set", id = "blocklist-push" }) | 158 local blocklist_push = st.iq({ type = "set", id = "blocklist-push" }) |
159 :add_child(act); -- I am lazy | 159 :add_child(action); -- I am lazy |
160 | 160 |
161 for _, session in pairs(sessions[username].sessions) do | 161 for _, session in pairs(sessions[username].sessions) do |
162 if session.interested_blocklist then | 162 if session.interested_blocklist then |
163 blocklist_push.attr.to = session.full_jid; | 163 blocklist_push.attr.to = session.full_jid; |
164 session.send(blocklist_push); | 164 session.send(blocklist_push); |