diff sat/plugins/plugin_xep_0313.py @ 3573:813595f88612

merge changes from main branch
author Goffi <goffi@goffi.org>
date Thu, 17 Jun 2021 13:05:58 +0200
parents 888109774673 4dad134a82c6
children 5245b675f7ad
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0313.py	Thu Jun 03 15:21:43 2021 +0200
+++ b/sat/plugins/plugin_xep_0313.py	Thu Jun 17 13:05:58 2021 +0200
@@ -80,6 +80,7 @@
         stanza_id_data = await self.host.memory.storage.getPrivates(
             mam.NS_MAM, [KEY_LAST_STANZA_ID], profile=client.profile)
         stanza_id = stanza_id_data.get(KEY_LAST_STANZA_ID)
+        rsm_req = None
         if stanza_id is None:
             log.info("can't retrieve last stanza ID, checking history")
             last_mess = await self.host.memory.historyGet(
@@ -89,10 +90,11 @@
             if not last_mess:
                 log.info(_("It seems that we have no MAM history yet"))
                 stanza_id = None
-                # FIXME: we should restrict starting of the archive, as it can be huge
+                rsm_req = rsm.RSMRequest(max_=50, before="")
             else:
                 stanza_id = last_mess[0][-1]['stanza_id']
-        rsm_req = rsm.RSMRequest(max_=100, after=stanza_id)
+        if rsm_req is None:
+            rsm_req = rsm.RSMRequest(max_=100, after=stanza_id)
         mam_req = mam.MAMRequest(rsm_=rsm_req)
         complete = False
         count = 0
@@ -103,6 +105,8 @@
             complete = mam_response["complete"]
             # we update MAM request for next iteration
             mam_req.rsm.after = rsm_response.last
+            # before may be set if we had no previous history
+            mam_req.rsm.before = None
             if not elt_list:
                 break
             else: