Software /
code /
prosody
Comparison
plugins/mod_storage_internal.lua @ 9903:2c5546cc5c70
mod_storage_internal: Implement a summary API returning message counts per contact
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 25 Feb 2019 15:48:28 +0100 |
parent | 9895:6bd65bff03b5 |
child | 9997:7c4631d7b6fb |
comparison
equal
deleted
inserted
replaced
9902:3eea63a68e0f | 9903:2c5546cc5c70 |
---|---|
194 local items, err = datamanager.list_load(username, host, self.store); | 194 local items, err = datamanager.list_load(username, host, self.store); |
195 if not items then return items, err; end | 195 if not items then return items, err; end |
196 return array(items):pluck("when"):map(datetime.date):unique(); | 196 return array(items):pluck("when"):map(datetime.date):unique(); |
197 end | 197 end |
198 | 198 |
199 function archive:summary(username, query) | |
200 local iter, err = self:find(username, query) | |
201 if not iter then return iter, err; end | |
202 local summary = {}; | |
203 for _, _, _, with in iter do | |
204 summary[with] = (summary[with] or 0) + 1; | |
205 end | |
206 return summary; | |
207 end | |
208 | |
199 function archive:delete(username, query) | 209 function archive:delete(username, query) |
200 local cache_key = jid_join(username, host, self.store); | 210 local cache_key = jid_join(username, host, self.store); |
201 if not query or next(query) == nil then | 211 if not query or next(query) == nil then |
202 archive_item_count_cache:set(cache_key, nil); | 212 archive_item_count_cache:set(cache_key, nil); |
203 return datamanager.list_store(username, host, self.store, nil); | 213 return datamanager.list_store(username, host, self.store, nil); |