# HG changeset patch # User Kim Alvefur # Date 1551106108 -3600 # Node ID 2c5546cc5c706a40b52576a12184fcb5d309754a # Parent 3eea63a68e0f4d95f19246b5f2d53fd4784fe53e mod_storage_internal: Implement a summary API returning message counts per contact diff -r 3eea63a68e0f -r 2c5546cc5c70 doc/storage.tld --- a/doc/storage.tld Sat Mar 23 08:52:57 2019 +0000 +++ b/doc/storage.tld Mon Feb 25 15:48:28 2019 +0100 @@ -47,6 +47,9 @@ -- 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 -r 3eea63a68e0f -r 2c5546cc5c70 plugins/mod_storage_internal.lua --- a/plugins/mod_storage_internal.lua Sat Mar 23 08:52:57 2019 +0000 +++ b/plugins/mod_storage_internal.lua Mon Feb 25 15:48:28 2019 +0100 @@ -196,6 +196,16 @@ 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