Mercurial > prosody-hg
comparison plugins/mod_blocklist.lua @ 6968:828a10e0464b
mod_blocklist: Rename variable for clarity
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 06 Dec 2015 02:07:15 +0100 |
| parents | d90a4d6a0e2c |
| children | 31d8e1a8a014 |
comparison
equal
deleted
inserted
replaced
| 6967:d90a4d6a0e2c | 6968:828a10e0464b |
|---|---|
| 121 end | 121 end |
| 122 item.attr.jid = jid; -- echo back prepped | 122 item.attr.jid = jid; -- echo back prepped |
| 123 new[jid] = is_contact_subscribed(username, module.host, jid) or false; | 123 new[jid] = is_contact_subscribed(username, module.host, jid) or false; |
| 124 end | 124 end |
| 125 | 125 |
| 126 local mode = action.name == "block" or nil; | 126 local is_blocking = action.name == "block" or nil; -- nil if unblocking |
| 127 | 127 |
| 128 if mode and not next(new) then | 128 if is_blocking and not next(new) then |
| 129 -- <block/> element does not contain at least one <item/> child element | 129 -- <block/> element does not contain at least one <item/> child element |
| 130 origin.send(st_error_reply(stanza, "modify", "bad-request")); | 130 origin.send(st_error_reply(stanza, "modify", "bad-request")); |
| 131 return true; | 131 return true; |
| 132 end | 132 end |
| 133 | 133 |
| 134 local blocklist = get_blocklist(username); | 134 local blocklist = get_blocklist(username); |
| 135 | 135 |
| 136 local new_blocklist = {}; | 136 local new_blocklist = {}; |
| 137 | 137 |
| 138 if mode or next(new) then | 138 if is_blocking or next(new) then |
| 139 for jid in pairs(blocklist) do | 139 for jid in pairs(blocklist) do |
| 140 new_blocklist[jid] = true; | 140 new_blocklist[jid] = true; |
| 141 end | 141 end |
| 142 for jid in pairs(new) do | 142 for jid in pairs(new) do |
| 143 new_blocklist[jid] = mode; | 143 new_blocklist[jid] = is_blocking; |
| 144 end | 144 end |
| 145 -- else empty the blocklist | 145 -- else empty the blocklist |
| 146 end | 146 end |
| 147 new_blocklist[false] = "not empty"; -- In order to avoid doing the migration thing twice | 147 new_blocklist[false] = "not empty"; -- In order to avoid doing the migration thing twice |
| 148 | 148 |
| 152 else | 152 else |
| 153 origin.send(st_error_reply(stanza, "wait", "internal-server-error", err)); | 153 origin.send(st_error_reply(stanza, "wait", "internal-server-error", err)); |
| 154 return true; | 154 return true; |
| 155 end | 155 end |
| 156 | 156 |
| 157 if mode then | 157 if is_blocking then |
| 158 for jid, in_roster in pairs(new) do | 158 for jid, in_roster in pairs(new) do |
| 159 if not blocklist[jid] and in_roster and sessions[username] then | 159 if not blocklist[jid] and in_roster and sessions[username] then |
| 160 for _, session in pairs(sessions[username].sessions) do | 160 for _, session in pairs(sessions[username].sessions) do |
| 161 if session.presence then | 161 if session.presence then |
| 162 module:send(st.presence({ type = "unavailable", to = jid, from = session.full_jid })); | 162 module:send(st.presence({ type = "unavailable", to = jid, from = session.full_jid })); |
