Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0313.py @ 3573:813595f88612
merge changes from main branch
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 17 Jun 2021 13:05:58 +0200 |
parents | 888109774673 4dad134a82c6 |
children | 5245b675f7ad |
comparison
equal
deleted
inserted
replaced
3541:888109774673 | 3573:813595f88612 |
---|---|
78 async def resume(self, client): | 78 async def resume(self, client): |
79 """Retrieve one2one messages received since the last we have in local storage""" | 79 """Retrieve one2one messages received since the last we have in local storage""" |
80 stanza_id_data = await self.host.memory.storage.getPrivates( | 80 stanza_id_data = await self.host.memory.storage.getPrivates( |
81 mam.NS_MAM, [KEY_LAST_STANZA_ID], profile=client.profile) | 81 mam.NS_MAM, [KEY_LAST_STANZA_ID], profile=client.profile) |
82 stanza_id = stanza_id_data.get(KEY_LAST_STANZA_ID) | 82 stanza_id = stanza_id_data.get(KEY_LAST_STANZA_ID) |
83 rsm_req = None | |
83 if stanza_id is None: | 84 if stanza_id is None: |
84 log.info("can't retrieve last stanza ID, checking history") | 85 log.info("can't retrieve last stanza ID, checking history") |
85 last_mess = await self.host.memory.historyGet( | 86 last_mess = await self.host.memory.historyGet( |
86 None, None, limit=1, filters={'not_types': C.MESS_TYPE_GROUPCHAT, | 87 None, None, limit=1, filters={'not_types': C.MESS_TYPE_GROUPCHAT, |
87 'last_stanza_id': True}, | 88 'last_stanza_id': True}, |
88 profile=client.profile) | 89 profile=client.profile) |
89 if not last_mess: | 90 if not last_mess: |
90 log.info(_("It seems that we have no MAM history yet")) | 91 log.info(_("It seems that we have no MAM history yet")) |
91 stanza_id = None | 92 stanza_id = None |
92 # FIXME: we should restrict starting of the archive, as it can be huge | 93 rsm_req = rsm.RSMRequest(max_=50, before="") |
93 else: | 94 else: |
94 stanza_id = last_mess[0][-1]['stanza_id'] | 95 stanza_id = last_mess[0][-1]['stanza_id'] |
95 rsm_req = rsm.RSMRequest(max_=100, after=stanza_id) | 96 if rsm_req is None: |
97 rsm_req = rsm.RSMRequest(max_=100, after=stanza_id) | |
96 mam_req = mam.MAMRequest(rsm_=rsm_req) | 98 mam_req = mam.MAMRequest(rsm_=rsm_req) |
97 complete = False | 99 complete = False |
98 count = 0 | 100 count = 0 |
99 while not complete: | 101 while not complete: |
100 mam_data = await self.getArchives(client, mam_req, | 102 mam_data = await self.getArchives(client, mam_req, |
101 service=client.jid.userhostJID()) | 103 service=client.jid.userhostJID()) |
102 elt_list, rsm_response, mam_response = mam_data | 104 elt_list, rsm_response, mam_response = mam_data |
103 complete = mam_response["complete"] | 105 complete = mam_response["complete"] |
104 # we update MAM request for next iteration | 106 # we update MAM request for next iteration |
105 mam_req.rsm.after = rsm_response.last | 107 mam_req.rsm.after = rsm_response.last |
108 # before may be set if we had no previous history | |
109 mam_req.rsm.before = None | |
106 if not elt_list: | 110 if not elt_list: |
107 break | 111 break |
108 else: | 112 else: |
109 count += len(elt_list) | 113 count += len(elt_list) |
110 | 114 |