# HG changeset patch # User Kim Alvefur # Date 1566515427 -7200 # Node ID 068692cb9e78e578d1eb4b3aa1a6fa38fc2bbc19 # Parent 1e2b444acb724031e8aa4db5343e69d24f929b1d mod_storage_*: Include timestamp of latest message in :summary API Clients may want to show a list of conversations ordered by how timestamp of most recent message. The counts allow a badge with unread message counter. diff -r 1e2b444acb72 -r 068692cb9e78 plugins/mod_storage_internal.lua --- a/plugins/mod_storage_internal.lua Fri Aug 23 01:04:00 2019 +0200 +++ b/plugins/mod_storage_internal.lua Fri Aug 23 01:10:27 2019 +0200 @@ -218,11 +218,14 @@ local iter, err = self:find(username, query) if not iter then return iter, err; end local counts = {}; - for _, _, _, with in iter do + local latest = {}; + for _, _, when, with in iter do counts[with] = (counts[with] or 0) + 1; + latest[with] = when; end return { counts = counts; + latest = latest; }; end diff -r 1e2b444acb72 -r 068692cb9e78 plugins/mod_storage_memory.lua --- a/plugins/mod_storage_memory.lua Fri Aug 23 01:04:00 2019 +0200 +++ b/plugins/mod_storage_memory.lua Fri Aug 23 01:10:27 2019 +0200 @@ -171,11 +171,14 @@ local iter, err = self:find(username, query) if not iter then return iter, err; end local counts = {}; - for _, _, _, with in iter do + local latest = {}; + for _, _, when, with in iter do counts[with] = (counts[with] or 0) + 1; + latest[with] = when; end return { counts = counts; + latest = latest; }; end diff -r 1e2b444acb72 -r 068692cb9e78 plugins/mod_storage_sql.lua --- a/plugins/mod_storage_sql.lua Fri Aug 23 01:04:00 2019 +0200 +++ b/plugins/mod_storage_sql.lua Fri Aug 23 01:10:27 2019 +0200 @@ -424,7 +424,7 @@ local user,store = username,self.store; local ok, result = engine:transaction(function() local sql_query = [[ - SELECT DISTINCT "with", COUNT(*) + SELECT DISTINCT "with", COUNT(*), MAX("when") FROM "prosodyarchive" WHERE %s GROUP BY "with" @@ -447,12 +447,15 @@ end); if not ok then return ok, result end local counts = {}; + local latest = {}; for row in result do local with, count = row[1], row[2]; counts[with] = count; + latest[with] = row[3]; end return { counts = counts; + latest = latest; }; end