# HG changeset patch # User Goffi # Date 1547307826 -3600 # Node ID 66fbf026ed492035fefe5123944cc9034ced198a # Parent 22832c1d2827622a003e90ea619b6eb803b2efca mam: set "complete" attribute when suitable diff -r 22832c1d2827 -r 66fbf026ed49 src/mam.py --- 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)