diff --git a/libervia/backend/plugins/plugin_xep_0313.py b/libervia/backend/plugins/plugin_xep_0313.py index 4ccdf834..0462ae75 100644 --- a/libervia/backend/plugins/plugin_xep_0313.py +++ b/libervia/backend/plugins/plugin_xep_0313.py @@ -171,12 +171,27 @@ class XEP_0313: assert mam_req.rsm is not None complete = False count = 0 + use_fallback = False while not complete: try: mam_data = await self.get_archives( client, mam_req, service=client.jid.userhostJID() ) except StanzaError as e: + if ( + stanza_id is not None + and not use_fallback + and e.condition == "item-not-found" + ): + log.warning( + f"Requested item (with stanza_id {stanza_id!r}) can't be " + f"found in history, archive has probably been purged on " + f"server. Falling back to last N items." + ) + use_fallback = True + rsm_req = rsm.RSMRequest(max_=50, before="") + mam_req = mam.MAMRequest(rsm_=rsm_req) + continue log.warning( f"Can't retrieve MAM archives: {e}\n" f"{xml_tools.p_fmt_elt(mam_req.toElement())}\n"