# HG changeset patch # User Kim Alvefur # Date 1566515040 -7200 # Node ID 1e2b444acb724031e8aa4db5343e69d24f929b1d # Parent d58925bb74ca16f1fe54f9105c8852125bc25ae1 mod_storage_*: Tweak :summary API to allow future expansion with more fields Eg might want to include last message, timestamp, chat state or other info. diff -r d58925bb74ca -r 1e2b444acb72 plugins/mod_storage_internal.lua --- a/plugins/mod_storage_internal.lua Thu Aug 22 01:00:31 2019 +0200 +++ b/plugins/mod_storage_internal.lua Fri Aug 23 01:04:00 2019 +0200 @@ -217,11 +217,13 @@ function archive:summary(username, query) local iter, err = self:find(username, query) if not iter then return iter, err; end - local summary = {}; + local counts = {}; for _, _, _, with in iter do - summary[with] = (summary[with] or 0) + 1; + counts[with] = (counts[with] or 0) + 1; end - return summary; + return { + counts = counts; + }; end function archive:users() diff -r d58925bb74ca -r 1e2b444acb72 plugins/mod_storage_memory.lua --- a/plugins/mod_storage_memory.lua Thu Aug 22 01:00:31 2019 +0200 +++ b/plugins/mod_storage_memory.lua Fri Aug 23 01:04:00 2019 +0200 @@ -170,11 +170,13 @@ function archive_store:summary(username, query) local iter, err = self:find(username, query) if not iter then return iter, err; end - local summary = {}; + local counts = {}; for _, _, _, with in iter do - summary[with] = (summary[with] or 0) + 1; + counts[with] = (counts[with] or 0) + 1; end - return summary; + return { + counts = counts; + }; end diff -r d58925bb74ca -r 1e2b444acb72 plugins/mod_storage_sql.lua --- a/plugins/mod_storage_sql.lua Thu Aug 22 01:00:31 2019 +0200 +++ b/plugins/mod_storage_sql.lua Fri Aug 23 01:04:00 2019 +0200 @@ -446,12 +446,14 @@ return engine:select(sql_query, unpack(args)); end); if not ok then return ok, result end - local summary = {}; + local counts = {}; for row in result do local with, count = row[1], row[2]; - summary[with] = count; + counts[with] = count; end - return summary; + return { + counts = counts; + }; end function archive_store:delete(username, query)