aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_storage_internal.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-10-09 01:02:17 +0200
committerKim Alvefur <zash@zash.se>2017-10-09 01:02:17 +0200
commit5091ef0c46c059b3cfe5bd8c2cb07547d2ea0d50 (patch)
treec13e2d311eb2b85942e651b08c91d572be9a82d4 /plugins/mod_storage_internal.lua
parent2477d1c2698cf220fdf8a18a4dbf045de954bc81 (diff)
downloadprosody-5091ef0c46c059b3cfe5bd8c2cb07547d2ea0d50.tar.gz
prosody-5091ef0c46c059b3cfe5bd8c2cb07547d2ea0d50.zip
mod_storage_internal: Add more extensive query support to archive:delete method
Diffstat (limited to 'plugins/mod_storage_internal.lua')
-rw-r--r--plugins/mod_storage_internal.lua28
1 files changed, 22 insertions, 6 deletions
diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua
index 9f44866a..c29319fc 100644
--- a/plugins/mod_storage_internal.lua
+++ b/plugins/mod_storage_internal.lua
@@ -160,9 +160,6 @@ function archive:delete(username, query)
if not query or next(query) == nil then
return datamanager.list_store(username, host, self.store, nil);
end
- for k in pairs(query) do
- if k ~= "end" then return nil, "unsupported-query-field"; end
- end
local items, err = datamanager.list_load(username, host, self.store);
if not items then
if err then
@@ -173,9 +170,28 @@ function archive:delete(username, query)
end
items = array(items);
local count_before = #items;
- items:filter(function (item)
- return item.when > query["end"];
- end);
+ if query then
+ if query.key then
+ items:filter(function (item)
+ return item.key ~= query.key;
+ end);
+ end
+ if query.with then
+ items:filter(function (item)
+ return item.with ~= query.with;
+ end);
+ end
+ if query.start then
+ items:filter(function (item)
+ return item.when < query.start;
+ end);
+ end
+ if query["end"] then
+ items:filter(function (item)
+ return item.when > query["end"];
+ end);
+ end
+ end
local count = count_before - #items;
local ok, err = datamanager.list_store(username, host, self.store, items);
if not ok then return ok, err; end