comparison src/mam.py @ 379:66fbf026ed49

mam: set "complete" attribute when suitable
author Goffi <goffi@goffi.org>
date Sat, 12 Jan 2019 16:43:46 +0100
parents 9a787881b824
children 845ed0f71dd6
comparison
equal deleted inserted replaced
378:22832c1d2827 379:66fbf026ed49
100 return message 100 return message
101 101
102 def cb(items_data): 102 def cb(items_data):
103 msg_data = [] 103 msg_data = []
104 rsm_elt = None 104 rsm_elt = None
105 attributes = {}
105 for item_data in items_data: 106 for item_data in items_data:
106 if item_data.item.name == 'set' and item_data.item.uri == rsm.NS_RSM: 107 if item_data.item.name == 'set' and item_data.item.uri == rsm.NS_RSM:
107 assert rsm_elt is None 108 assert rsm_elt is None
108 rsm_elt = item_data.item 109 rsm_elt = item_data.item
110 # XXX: we check if it is the last page using initial request data
111 # and RSM element data. In this case, we must have the "complete"
112 # attribute set to "true".
113 page_max = (int(rsm_elt.first['index']) + 1) * mam_request.rsm.max
114 count = int(unicode(rsm_elt.count))
115 if page_max >= count:
116 # the maximum items which can be displayed is equal to or above
117 # the total number of items, which means we are complete
118 attributes['complete'] = "true"
109 elif item_data.item.name == 'item': 119 elif item_data.item.name == 'item':
110 msg_data.append([item_data.item['id'], make_message(item_data.item), item_data.created]) 120 msg_data.append([item_data.item['id'], make_message(item_data.item), item_data.created])
111 else: 121 else:
112 log.msg("WARNING: unknown element: {}".format(item_data.item.name)) 122 log.msg("WARNING: unknown element: {}".format(item_data.item.name))
113 if pep: 123 if pep:
115 # so me manage the sending ourself, and return 125 # so me manage the sending ourself, and return
116 # an empty msg_data list to avoid double sending 126 # an empty msg_data list to avoid double sending
117 for data in msg_data: 127 for data in msg_data:
118 self.forwardPEPMessage(mam_request, *data) 128 self.forwardPEPMessage(mam_request, *data)
119 msg_data = [] 129 msg_data = []
120 return (msg_data, rsm_elt) 130 return (msg_data, rsm_elt, attributes)
121 131
122 d.addErrback(self._mapErrors) 132 d.addErrback(self._mapErrors)
123 d.addCallback(cb) 133 d.addCallback(cb)
124 return d 134 return d
125 135