comparison sat/plugins/plugin_xep_0313.py @ 3715:b9718216a1c0 0.9

merge bookmark 0.9
author Goffi <goffi@goffi.org>
date Wed, 01 Dec 2021 16:13:31 +0100
parents 813595f88612
children 5245b675f7ad
comparison
equal deleted inserted replaced
3714:af09b5aaa5d7 3715:b9718216a1c0
73 host.bridge.addMethod( 73 host.bridge.addMethod(
74 "MAMGet", ".plugin", in_sign='sss', 74 "MAMGet", ".plugin", in_sign='sss',
75 out_sign='(a(sdssa{ss}a{ss}ss)ss)', method=self._getArchives, 75 out_sign='(a(sdssa{ss}a{ss}ss)ss)', method=self._getArchives,
76 async_=True) 76 async_=True)
77 77
78 @defer.inlineCallbacks 78 async def resume(self, client):
79 def resume(self, client):
80 """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"""
81 stanza_id_data = yield self.host.memory.storage.getPrivates( 80 stanza_id_data = await self.host.memory.storage.getPrivates(
82 mam.NS_MAM, [KEY_LAST_STANZA_ID], profile=client.profile) 81 mam.NS_MAM, [KEY_LAST_STANZA_ID], profile=client.profile)
83 stanza_id = stanza_id_data.get(KEY_LAST_STANZA_ID) 82 stanza_id = stanza_id_data.get(KEY_LAST_STANZA_ID)
84 rsm_req = None 83 rsm_req = None
85 if stanza_id is None: 84 if stanza_id is None:
86 log.info("can't retrieve last stanza ID, checking history") 85 log.info("can't retrieve last stanza ID, checking history")
87 last_mess = yield self.host.memory.historyGet( 86 last_mess = await self.host.memory.historyGet(
88 None, None, limit=1, filters={'not_types': C.MESS_TYPE_GROUPCHAT, 87 None, None, limit=1, filters={'not_types': C.MESS_TYPE_GROUPCHAT,
89 'last_stanza_id': True}, 88 'last_stanza_id': True},
90 profile=client.profile) 89 profile=client.profile)
91 if not last_mess: 90 if not last_mess:
92 log.info(_("It seems that we have no MAM history yet")) 91 log.info(_("It seems that we have no MAM history yet"))
98 rsm_req = rsm.RSMRequest(max_=100, after=stanza_id) 97 rsm_req = rsm.RSMRequest(max_=100, after=stanza_id)
99 mam_req = mam.MAMRequest(rsm_=rsm_req) 98 mam_req = mam.MAMRequest(rsm_=rsm_req)
100 complete = False 99 complete = False
101 count = 0 100 count = 0
102 while not complete: 101 while not complete:
103 mam_data = yield self.getArchives(client, mam_req, 102 mam_data = await self.getArchives(client, mam_req,
104 service=client.jid.userhostJID()) 103 service=client.jid.userhostJID())
105 elt_list, rsm_response, mam_response = mam_data 104 elt_list, rsm_response, mam_response = mam_data
106 complete = mam_response["complete"] 105 complete = mam_response["complete"]
107 # we update MAM request for next iteration 106 # we update MAM request for next iteration
108 mam_req.rsm.after = rsm_response.last 107 mam_req.rsm.after = rsm_response.last
143 from_jid=from_jid.full(), xml=mess_elt.toXml())) 142 from_jid=from_jid.full(), xml=mess_elt.toXml()))
144 continue 143 continue
145 # adding message to history 144 # adding message to history
146 mess_data = client.messageProt.parseMessage(fwd_message_elt) 145 mess_data = client.messageProt.parseMessage(fwd_message_elt)
147 try: 146 try:
148 yield client.messageProt.addToHistory(mess_data) 147 await client.messageProt.addToHistory(mess_data)
149 except exceptions.CancelError as e: 148 except exceptions.CancelError as e:
150 log.warning( 149 log.warning(
151 "message has not been added to history: {e}".format(e=e)) 150 "message has not been added to history: {e}".format(e=e))
152 except Exception as e: 151 except Exception as e:
153 log.error( 152 log.error(
158 log.info(_("We have received no message while offline")) 157 log.info(_("We have received no message while offline"))
159 else: 158 else:
160 log.info(_("We have received {num_mess} message(s) while offline.") 159 log.info(_("We have received {num_mess} message(s) while offline.")
161 .format(num_mess=count)) 160 .format(num_mess=count))
162 161
163 def profileConnected(self, client): 162 async def profileConnected(self, client):
164 return self.resume(client) 163 await self.resume(client)
165 164
166 def getHandler(self, client): 165 def getHandler(self, client):
167 mam_client = client._mam = SatMAMClient(self) 166 mam_client = client._mam = SatMAMClient(self)
168 return mam_client 167 return mam_client
169 168