Software /
code /
prosody
Comparison
plugins/mod_blocklist.lua @ 6973:f350f840a6f7
mod_blocklist: Restructure how we keep track of where to send unavailable presence
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 06 Dec 2015 02:22:49 +0100 |
parent | 6972:9e926e48cbf9 |
child | 6974:bdb216e0688a |
comparison
equal
deleted
inserted
replaced
6972:9e926e48cbf9 | 6973:f350f840a6f7 |
---|---|
117 local origin, stanza = event.origin, event.stanza; | 117 local origin, stanza = event.origin, event.stanza; |
118 local username = origin.username; | 118 local username = origin.username; |
119 local action = stanza.tags[1]; -- "block" or "unblock" | 119 local action = stanza.tags[1]; -- "block" or "unblock" |
120 local new = {}; -- JIDs to block depending or unblock on action | 120 local new = {}; -- JIDs to block depending or unblock on action |
121 | 121 |
122 -- XEP-0191 sayeth: | |
123 -- > When the user blocks communications with the contact, the user's | |
124 -- > server MUST send unavailable presence information to the contact (but | |
125 -- > only if the contact is allowed to receive presence notifications [...] | |
126 -- So contacts we need to do that for are added to the set below. | |
127 local send_unavailable = {}; | |
128 | |
122 for item in action:childtags("item") do | 129 for item in action:childtags("item") do |
123 local jid = jid_prep(item.attr.jid); | 130 local jid = jid_prep(item.attr.jid); |
124 if not jid then | 131 if not jid then |
125 origin.send(st_error_reply(stanza, "modify", "jid-malformed")); | 132 origin.send(st_error_reply(stanza, "modify", "jid-malformed")); |
126 return true; | 133 return true; |
127 end | 134 end |
128 item.attr.jid = jid; -- echo back prepped | 135 item.attr.jid = jid; -- echo back prepped |
129 new[jid] = is_contact_subscribed(username, module.host, jid) or false; | 136 new[jid] = true; |
137 if is_contact_subscribed(username, module.host, jid) then | |
138 send_unavailable[jid] = true; | |
139 end | |
130 end | 140 end |
131 | 141 |
132 local is_blocking = action.name == "block" or nil; -- nil if unblocking | 142 local is_blocking = action.name == "block" or nil; -- nil if unblocking |
133 | 143 |
134 if is_blocking and not next(new) then | 144 if is_blocking and not next(new) then |
159 origin.send(st_error_reply(stanza, "wait", "internal-server-error", err)); | 169 origin.send(st_error_reply(stanza, "wait", "internal-server-error", err)); |
160 return true; | 170 return true; |
161 end | 171 end |
162 | 172 |
163 if is_blocking then | 173 if is_blocking then |
164 for jid, in_roster in pairs(new) do | 174 for jid in pairs(send_unavailable) do |
165 if not blocklist[jid] and in_roster then | 175 if not blocklist[jid] then |
166 for _, session in pairs(sessions[username].sessions) do | 176 for _, session in pairs(sessions[username].sessions) do |
167 if session.presence then | 177 if session.presence then |
168 module:send(st.presence({ type = "unavailable", to = jid, from = session.full_jid })); | 178 module:send(st.presence({ type = "unavailable", to = jid, from = session.full_jid })); |
169 end | 179 end |
170 end | 180 end |