mod_blocking: Ensure that a JID can be in the blocklist at most once, and have helper functions return true/false on success/error
--- a/mod_blocking/mod_blocking.lua Mon Jun 14 01:04:58 2010 +0500
+++ b/mod_blocking/mod_blocking.lua Mon Jun 14 12:25:53 2010 +0100
@@ -21,7 +21,11 @@
local items = default_list.items;
local order = items[1] and items[1].order or 0; -- Must come first
for i=1,#items do -- order must be unique
- items[i].order = items[i].order + 1;
+ local item = items[i];
+ item.order = item.order + 1;
+ if item.type == "jid" and item.action == "deny" and item.value == jid then
+ return false;
+ end
end
table.insert(items, 1, { type = "jid"
, action = "deny"
@@ -33,6 +37,7 @@
, order = order
});
datamanager.store(username, host, "privacy", privacy_lists);
+ return true;
end
-- Remove JID from default privacy list
@@ -43,15 +48,19 @@
local default_list = privacy_lists.lists[default_list_name];
if not default_list then return; end
local items = default_list.items;
- local item;
+ local item, removed = nil, false;
for i=1,#items do -- order must be unique
item = items[i];
if item.type == "jid" and item.action == "deny" and item.value == jid then
table.remove(items, i);
- return true;
+ removed = true;
+ break;
end
end
- datamanager.store(username, host, "privacy", privacy_lists);
+ if removed then
+ datamanager.store(username, host, "privacy", privacy_lists);
+ end
+ return removed;
end
function remove_all_blocked_jids(username, host)
@@ -69,6 +78,7 @@
end
end
datamanager.store(username, host, "privacy", privacy_lists);
+ return true;
end
function get_blocked_jids(username, host)