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.
This commit is contained in:
Goffi 2026-08-10 12:01:01 +02:00
commit 1bfc7bd10b

View file

@ -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"