comparison sat/plugins/plugin_xep_0045.py @ 2724:35a0ab3032bb

plugin XEP-0045: don't loop when initiating MAM archive
author Goffi <goffi@goffi.org>
date Wed, 12 Dec 2018 08:58:52 +0100
parents c6be5962752d
children 1b11da85492c
comparison
equal deleted inserted replaced
2723:c6be5962752d 2724:35a0ab3032bb
869 filters={u'last_stanza_id': True}, 869 filters={u'last_stanza_id': True},
870 profile=client.profile) 870 profile=client.profile)
871 if last_mess: 871 if last_mess:
872 stanza_id = last_mess[0][-1][u'stanza_id'] 872 stanza_id = last_mess[0][-1][u'stanza_id']
873 rsm_req = rsm.RSMRequest(max_=100, after=stanza_id) 873 rsm_req = rsm.RSMRequest(max_=100, after=stanza_id)
874 no_loop=False
874 else: 875 else:
875 log.info(u"We have no MAM archive for room {room_jid}.".format( 876 log.info(u"We have no MAM archive for room {room_jid}.".format(
876 room_jid=room_jid)) 877 room_jid=room_jid))
877 # we don't want the whole archive if we have no archive yet 878 # we don't want the whole archive if we have no archive yet
878 # as it can be huge 879 # as it can be huge
879 rsm_req = rsm.RSMRequest(max_=50, before=u'') 880 rsm_req = rsm.RSMRequest(max_=50, before=u'')
881 no_loop=True
880 882
881 mam_req = mam.MAMRequest(rsm_=rsm_req) 883 mam_req = mam.MAMRequest(rsm_=rsm_req)
882 complete = False 884 complete = False
883 count = 0 885 count = 0
884 while not complete: 886 while not complete:
885 mam_data = yield self._mam.getArchives(client, mam_req, 887 mam_data = yield self._mam.getArchives(client, mam_req,
886 service=room_jid) 888 service=room_jid)
887 elt_list, rsm_response, mam_response = mam_data 889 elt_list, rsm_response, mam_response = mam_data
888 complete = mam_response[u"complete"] 890 complete = True if no_loop else mam_response[u"complete"]
889 # we update MAM request for next iteration 891 # we update MAM request for next iteration
890 mam_req.rsm.after = rsm_response.last 892 mam_req.rsm.after = rsm_response.last
891 893
892 if not elt_list: 894 if not elt_list:
893 break 895 break