Mercurial > libervia-pubsub
changeset 379:66fbf026ed49
mam: set "complete" attribute when suitable
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 12 Jan 2019 16:43:46 +0100 |
parents | 22832c1d2827 |
children | e81964db3cd6 |
files | src/mam.py |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/mam.py Sat Jan 12 16:41:45 2019 +0100 +++ b/src/mam.py Sat Jan 12 16:43:46 2019 +0100 @@ -102,10 +102,20 @@ def cb(items_data): msg_data = [] rsm_elt = None + attributes = {} for item_data in items_data: if item_data.item.name == 'set' and item_data.item.uri == rsm.NS_RSM: assert rsm_elt is None rsm_elt = item_data.item + # XXX: we check if it is the last page using initial request data + # and RSM element data. In this case, we must have the "complete" + # attribute set to "true". + page_max = (int(rsm_elt.first['index']) + 1) * mam_request.rsm.max + count = int(unicode(rsm_elt.count)) + if page_max >= count: + # the maximum items which can be displayed is equal to or above + # the total number of items, which means we are complete + attributes['complete'] = "true" elif item_data.item.name == 'item': msg_data.append([item_data.item['id'], make_message(item_data.item), item_data.created]) else: @@ -117,7 +127,7 @@ for data in msg_data: self.forwardPEPMessage(mam_request, *data) msg_data = [] - return (msg_data, rsm_elt) + return (msg_data, rsm_elt, attributes) d.addErrback(self._mapErrors) d.addCallback(cb)