From 6426103f121008d39a95f55ad444e64f5dbfbd3f Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 10 Jun 2021 15:44:30 +0200 Subject: [PATCH] plugin XEP-0313: on cold start (without known archive) we only request 50 last messages --- sat/plugins/plugin_xep_0313.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sat/plugins/plugin_xep_0313.py b/sat/plugins/plugin_xep_0313.py index 39ecc7b8..3ad0fd6d 100644 --- a/sat/plugins/plugin_xep_0313.py +++ b/sat/plugins/plugin_xep_0313.py @@ -81,6 +81,7 @@ class XEP_0313(object): stanza_id_data = yield 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 = yield self.host.memory.historyGet( @@ -90,10 +91,11 @@ class XEP_0313(object): 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 @@ -104,6 +106,8 @@ class XEP_0313(object): 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: