From 1bfc7bd10b0e0f907139cc96234f48dfa0518901 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 10 Aug 2026 12:01:01 +0200 Subject: [PATCH] plugin XEP-0313: fallback to last N items in case of missing item: If a reference item is missing (e.g., after server purge) we now fallback to last N items (50 for now), instead of giving up. --- libervia/backend/plugins/plugin_xep_0313.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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"