aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-02-25 15:48:28 +0100
committerKim Alvefur <zash@zash.se>2019-02-25 15:48:28 +0100
commit582fa3f46f105fe55447d607dceb43b5ac61d440 (patch)
tree21f89ef04949ba04cad55d6d93b4e97b66709053
parent3c50aa4902aada8eccbdd32f359a0cd6a52aceae (diff)
downloadprosody-582fa3f46f105fe55447d607dceb43b5ac61d440.tar.gz
prosody-582fa3f46f105fe55447d607dceb43b5ac61d440.zip
mod_storage_internal: Implement a summary API returning message counts per contact
-rw-r--r--doc/storage.tld3
-rw-r--r--plugins/mod_storage_internal.lua10
2 files changed, 13 insertions, 0 deletions
diff --git a/doc/storage.tld b/doc/storage.tld
index f1d33e58..057649a4 100644
--- a/doc/storage.tld
+++ b/doc/storage.tld
@@ -47,6 +47,9 @@ interface archive_store
-- Array of dates which do have messages (Optional?)
dates : ( self, string? ) -> ({ string }) | (nil, string)
+
+ -- Map of counts per "with" field
+ summary : ( self, string?, archive_query? ) -> ( { string : integer } ) | (nil, string)
end
-- This represents moduleapi
diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua
index c87d01be..aa5c3c8a 100644
--- a/plugins/mod_storage_internal.lua
+++ b/plugins/mod_storage_internal.lua
@@ -196,6 +196,16 @@ function archive:dates(username)
return array(items):pluck("when"):map(datetime.date):unique();
end
+function archive:summary(username, query)
+ local iter, err = self:find(username, query)
+ if not iter then return iter, err; end
+ local summary = {};
+ for _, _, _, with in iter do
+ summary[with] = (summary[with] or 0) + 1;
+ end
+ return summary;
+end
+
function archive:delete(username, query)
local cache_key = jid_join(username, host, self.store);
if not query or next(query) == nil then