comparison plugins/mod_blocklist.lua @ 6354:bbb4a82db32e

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Wed, 13 Aug 2014 19:22:08 +0200
parents b703e6930e4c
children 6d3187f24608
comparison
equal deleted inserted replaced
6349:0cee68dd35f8 6354:bbb4a82db32e
96 end 96 end
97 origin.interested_blocklist = true; -- Gets notified about changes 97 origin.interested_blocklist = true; -- Gets notified about changes
98 return origin.send(reply); 98 return origin.send(reply);
99 end); 99 end);
100 100
101 -- Add or remove a bare jid 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
125 125
126 local blocklist = get_blocklist(username); 126 local blocklist = get_blocklist(username);
127 127
128 local new_blocklist = {}; 128 local new_blocklist = {};
129 129
130 if mode and next(new) then 130 if mode or next(new) then
131 for jid in pairs(blocklist) do 131 for jid in pairs(blocklist) do
132 new_blocklist[jid] = true; 132 new_blocklist[jid] = true;
133 end 133 end
134 for jid in pairs(new) do 134 for jid in pairs(new) do
135 new_blocklist[jid] = mode; 135 new_blocklist[jid] = mode;
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);