comparison sat/plugins/plugin_xep_0313.py @ 3561:4dad134a82c6

plugin XEP-0313: on cold start (without known archive) we only request 50 last messages
author Goffi <goffi@goffi.org>
date Thu, 10 Jun 2021 15:44:30 +0200
parents be6d91572633
children 813595f88612
comparison
equal deleted inserted replaced
3560:413e96caa682 3561:4dad134a82c6
79 def resume(self, client): 79 def resume(self, client):
80 """Retrieve one2one messages received since the last we have in local storage""" 80 """Retrieve one2one messages received since the last we have in local storage"""
81 stanza_id_data = yield self.host.memory.storage.getPrivates( 81 stanza_id_data = yield self.host.memory.storage.getPrivates(
82 mam.NS_MAM, [KEY_LAST_STANZA_ID], profile=client.profile) 82 mam.NS_MAM, [KEY_LAST_STANZA_ID], profile=client.profile)
83 stanza_id = stanza_id_data.get(KEY_LAST_STANZA_ID) 83 stanza_id = stanza_id_data.get(KEY_LAST_STANZA_ID)
84 rsm_req = None
84 if stanza_id is None: 85 if stanza_id is None:
85 log.info("can't retrieve last stanza ID, checking history") 86 log.info("can't retrieve last stanza ID, checking history")
86 last_mess = yield self.host.memory.historyGet( 87 last_mess = yield self.host.memory.historyGet(
87 None, None, limit=1, filters={'not_types': C.MESS_TYPE_GROUPCHAT, 88 None, None, limit=1, filters={'not_types': C.MESS_TYPE_GROUPCHAT,
88 'last_stanza_id': True}, 89 'last_stanza_id': True},
89 profile=client.profile) 90 profile=client.profile)
90 if not last_mess: 91 if not last_mess:
91 log.info(_("It seems that we have no MAM history yet")) 92 log.info(_("It seems that we have no MAM history yet"))
92 stanza_id = None 93 stanza_id = None
93 # FIXME: we should restrict starting of the archive, as it can be huge 94 rsm_req = rsm.RSMRequest(max_=50, before="")
94 else: 95 else:
95 stanza_id = last_mess[0][-1]['stanza_id'] 96 stanza_id = last_mess[0][-1]['stanza_id']
96 rsm_req = rsm.RSMRequest(max_=100, after=stanza_id) 97 if rsm_req is None:
98 rsm_req = rsm.RSMRequest(max_=100, after=stanza_id)
97 mam_req = mam.MAMRequest(rsm_=rsm_req) 99 mam_req = mam.MAMRequest(rsm_=rsm_req)
98 complete = False 100 complete = False
99 count = 0 101 count = 0
100 while not complete: 102 while not complete:
101 mam_data = yield self.getArchives(client, mam_req, 103 mam_data = yield self.getArchives(client, mam_req,
102 service=client.jid.userhostJID()) 104 service=client.jid.userhostJID())
103 elt_list, rsm_response, mam_response = mam_data 105 elt_list, rsm_response, mam_response = mam_data
104 complete = mam_response["complete"] 106 complete = mam_response["complete"]
105 # we update MAM request for next iteration 107 # we update MAM request for next iteration
106 mam_req.rsm.after = rsm_response.last 108 mam_req.rsm.after = rsm_response.last
109 # before may be set if we had no previous history
110 mam_req.rsm.before = None
107 if not elt_list: 111 if not elt_list:
108 break 112 break
109 else: 113 else:
110 count += len(elt_list) 114 count += len(elt_list)
111 115