changeset 488:c41f37f1b51c

mam: fix `complete` attribute setting in `onArchiveRequest`
author Goffi <goffi@goffi.org>
date Sun, 02 Oct 2022 16:46:04 +0200
parents 7a23db86ee65
children fa0d2a4783fa
files sat_pubsub/mam.py
diffstat 1 files changed, 13 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/sat_pubsub/mam.py	Sun Oct 02 16:26:48 2022 +0200
+++ b/sat_pubsub/mam.py	Sun Oct 02 16:46:04 2022 +0200
@@ -106,27 +106,21 @@
         def cb(items_data_tuple):
             items_data, rsm_response = items_data_tuple
             msg_data = []
-            rsm_elt = None
             attributes = {}
+            if rsm_response:
+                rsm_elt = rsm_response.toElement()
+                # 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 = rsm_response.index + mam_request.rsm.max
+                if page_max >= rsm_response.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"
+            else:
+                rsm_elt = None
             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
-                    if rsm_elt.first:
-                        # 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']) +  mam_request.rsm.max
-                        count = int(str(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"
-                    else:
-                        log.msg("WARNING: no <first> element in RSM request: {xml}".format(
-                            xml = rsm_elt.toXml().encode('utf-8')))
-                elif item_data.item.name == 'item':
+                if item_data.item.name == 'item':
                     msg_data.append([item_data.item['id'], make_message(item_data.item),
                                      item_data.created])
                 else: