diff --git a/sat/plugins/plugin_xep_0045.py b/sat/plugins/plugin_xep_0045.py index f465f9e6..7ecf75e5 100644 --- a/sat/plugins/plugin_xep_0045.py +++ b/sat/plugins/plugin_xep_0045.py @@ -20,9 +20,9 @@ from sat.core.i18n import _, D_ from sat.core.constants import Const as C from sat.core.log import getLogger -log = getLogger(__name__) from twisted.internet import defer from twisted.words.protocols.jabber import jid +from twisted.words.protocols.jabber import error as xmpp_error from twisted.python import failure from sat.core import exceptions @@ -41,6 +41,9 @@ from wokkel import rsm from wokkel import mam +log = getLogger(__name__) + + PLUGIN_INFO = { C.PI_NAME: "XEP-0045 Plugin", C.PI_IMPORT_NAME: "XEP-0045", @@ -979,8 +982,22 @@ class SatMUCClient(muc.MUCClient): complete = False count = 0 while not complete: - mam_data = yield self._mam.getArchives(client, mam_req, - service=room_jid) + try: + mam_data = yield self._mam.getArchives(client, mam_req, + service=room_jid) + except xmpp_error.StanzaError as e: + if last_mess and e.condition == 'item-not-found': + log.info( + f"requested item (with id {stanza_id!r}) can't be found in " + f"history of {room_jid}, history has probably been purged on " + f"server.") + # we get last items like for a new room + rsm_req = rsm.RSMRequest(max_=50, before='') + mam_req = mam.MAMRequest(rsm_=rsm_req) + no_loop=True + continue + else: + raise e elt_list, rsm_response, mam_response = mam_data complete = True if no_loop else mam_response["complete"] # we update MAM request for next iteration