Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0045.py @ 3080:16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Some servers don't store permanently the whole history of MUC with MAM. As a result, an
"item-not-found" stanza error can be received when message id used as reference doesn't exist
anymore on the server.
When this case happens, the history is retrieved in the same way as for a newly joined room
(i.e. last 50 messages are requested).
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 05 Dec 2019 23:05:16 +0100 |
parents | 730bbed77a89 |
children | 13be04a70e2f |
comparison
equal
deleted
inserted
replaced
3079:f8cc88c773c8 | 3080:16925f494820 |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _, D_ | 20 from sat.core.i18n import _, D_ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | |
24 from twisted.internet import defer | 23 from twisted.internet import defer |
25 from twisted.words.protocols.jabber import jid | 24 from twisted.words.protocols.jabber import jid |
25 from twisted.words.protocols.jabber import error as xmpp_error | |
26 from twisted.python import failure | 26 from twisted.python import failure |
27 | 27 |
28 from sat.core import exceptions | 28 from sat.core import exceptions |
29 from sat.memory import memory | 29 from sat.memory import memory |
30 | 30 |
37 from zope.interface import implementer | 37 from zope.interface import implementer |
38 | 38 |
39 # XXX: mam and rsm come from sat_tmp.wokkel | 39 # XXX: mam and rsm come from sat_tmp.wokkel |
40 from wokkel import rsm | 40 from wokkel import rsm |
41 from wokkel import mam | 41 from wokkel import mam |
42 | |
43 | |
44 log = getLogger(__name__) | |
42 | 45 |
43 | 46 |
44 PLUGIN_INFO = { | 47 PLUGIN_INFO = { |
45 C.PI_NAME: "XEP-0045 Plugin", | 48 C.PI_NAME: "XEP-0045 Plugin", |
46 C.PI_IMPORT_NAME: "XEP-0045", | 49 C.PI_IMPORT_NAME: "XEP-0045", |
977 | 980 |
978 mam_req = mam.MAMRequest(rsm_=rsm_req) | 981 mam_req = mam.MAMRequest(rsm_=rsm_req) |
979 complete = False | 982 complete = False |
980 count = 0 | 983 count = 0 |
981 while not complete: | 984 while not complete: |
982 mam_data = yield self._mam.getArchives(client, mam_req, | 985 try: |
983 service=room_jid) | 986 mam_data = yield self._mam.getArchives(client, mam_req, |
987 service=room_jid) | |
988 except xmpp_error.StanzaError as e: | |
989 if last_mess and e.condition == 'item-not-found': | |
990 log.info( | |
991 f"requested item (with id {stanza_id!r}) can't be found in " | |
992 f"history of {room_jid}, history has probably been purged on " | |
993 f"server.") | |
994 # we get last items like for a new room | |
995 rsm_req = rsm.RSMRequest(max_=50, before='') | |
996 mam_req = mam.MAMRequest(rsm_=rsm_req) | |
997 no_loop=True | |
998 continue | |
999 else: | |
1000 raise e | |
984 elt_list, rsm_response, mam_response = mam_data | 1001 elt_list, rsm_response, mam_response = mam_data |
985 complete = True if no_loop else mam_response["complete"] | 1002 complete = True if no_loop else mam_response["complete"] |
986 # we update MAM request for next iteration | 1003 # we update MAM request for next iteration |
987 mam_req.rsm.after = rsm_response.last | 1004 mam_req.rsm.after = rsm_response.last |
988 | 1005 |