def retrieve(self, jid=None, start=None, end=None, with_jid=None, ifrom=None, timeout=None, callback=None, iterator=False, rsm=None): iq = self.xmpp.Iq() query_id = iq['id'] iq['to'] = jid iq['from'] = ifrom iq['type'] = 'set' iq['mam']['queryid'] = query_id iq['mam']['start'] = start iq['mam']['end'] = end iq['mam']['with'] = with_jid if rsm: for key, value in rsm.items(): iq['mam']['rsm'][key] = str(value) cb_data = {} def pre_cb(query): query['mam']['queryid'] = query['id'] collector = Collector( 'MAM_Results_%s' % query_id, StanzaPath('message/mam_result@queryid=%s' % query['id'])) self.xmpp.register_handler(collector) cb_data['collector'] = collector def post_cb(result): results = cb_data['collector'].stop() if result['type'] == 'result': result['mam']['results'] = results if iterator: return self.xmpp['xep_0059'].iterate(iq, 'mam', 'results', recv_interface='mam_fin', pre_cb=pre_cb, post_cb=post_cb) collector = Collector( 'MAM_Results_%s' % query_id, StanzaPath('message/mam_result@queryid=%s' % query_id)) self.xmpp.register_handler(collector) def wrapped_cb(iq): results = collector.stop() if iq['type'] == 'result': iq['mam']['results'] = results if callback: callback(iq) return iq.send(timeout=timeout, callback=wrapped_cb)
def pre_cb(query): query['mam']['queryid'] = query['id'] collector = Collector( 'MAM_Results_%s' % query_id, StanzaPath('message/mam_result@queryid=%s' % query['id'])) self.xmpp.register_handler(collector) cb_data['collector'] = collector
def retrieve(self, jid=None, start=None, end=None, with_jid=None, ifrom=None, timeout=None, callback=None, iterator=False): iq = self.xmpp.Iq() query_id = iq['id'] iq['to'] = jid iq['from'] = ifrom iq['type'] = 'get' iq['mam']['queryid'] = query_id iq['mam']['start'] = start iq['mam']['end'] = end iq['mam']['with'] = with_jid collector = Collector( 'MAM_Results_%s' % query_id, StanzaPath('message/mam_result@queryid=%s' % query_id)) self.xmpp.register_handler(collector) if iterator: return self.xmpp['xep_0059'].iterate(iq, 'mam', 'results') def wrapped_cb(iq): results = collector.stop() if iq['type'] == 'result': iq['mam']['results'] = results callback(iq) return iq.send(timeout=timeout, callback=wrapped_cb)
def view(self, nodes, ifrom=None, timeout=None, callback=None, timeout_callback=None): if not isinstance(nodes, (list, set)): nodes = [nodes] iq = self.xmpp.Iq() iq['type'] = 'get' iq['from'] = ifrom offline = iq['offline'] for node in nodes: item = stanza.Item() item['node'] = node item['action'] = 'view' offline.append(item) collector = Collector( 'Offline_Results_%s' % iq['id'], StanzaPath('message/offline')) self.xmpp.register_handler(collector) def wrapped_cb(iq): results = collector.stop() if iq['type'] == 'result': iq['offline']['results'] = results callback(iq) iq.send(timeout=timeout, callback=wrapped_cb, timeout_callback=timeout_callback)
def pre_cb(query: Iq) -> None: stanza_mask['mam_result']['queryid'] = query['id'] xml_mask = str(stanza_mask) query['mam']['queryid'] = query['id'] collector = Collector('MAM_Results_%s' % query_id, MatchXMLMask(xml_mask)) self.xmpp.register_handler(collector) cb_data['collector'] = collector
def fetch(self, ifrom=None, timeout=None, callback=None, timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom iq['offline']['fetch'] = True collector = Collector( 'Offline_Results_%s' % iq['id'], StanzaPath('message/offline')) self.xmpp.register_handler(collector) def wrapped_cb(iq): results = collector.stop() if iq['type'] == 'result': iq['offline']['results'] = results callback(iq) iq.send(timeout=timeout, callback=wrapped_cb, timeout_callback=timeout_callback)
def retrieve(self, jid: Optional[JID] = None, start: Optional[datetime] = None, end: Optional[datetime] = None, with_jid: Optional[JID] = None, ifrom: Optional[JID] = None, reverse: bool = False, timeout: int = None, callback: Callable[[Iq], None] = None, iterator: bool = False, rsm: Optional[Dict[str, Any]] = None) -> Awaitable: """ Send a MAM query and retrieve the results. :param JID jid: Entity holding the MAM records :param datetime start,end: MAM query temporal boundaries :param JID with_jid: Filter results on this JID :param JID ifrom: To change the from address of the query :param bool reverse: Get the results in reverse order :param int timeout: IQ timeout :param func callback: Custom callback for handling results :param bool iterator: Use RSM and iterate over a paginated query :param dict rsm: RSM custom options """ iq, stanza_mask = self._pre_mam_retrieve(jid, start, end, with_jid, ifrom) query_id = iq['id'] amount = 10 if rsm: for key, value in rsm.items(): iq['mam']['rsm'][key] = str(value) if key == 'max': amount = value cb_data = {} xml_mask = str(stanza_mask) def pre_cb(query: Iq) -> None: stanza_mask['mam_result']['queryid'] = query['id'] xml_mask = str(stanza_mask) query['mam']['queryid'] = query['id'] collector = Collector('MAM_Results_%s' % query_id, MatchXMLMask(xml_mask)) self.xmpp.register_handler(collector) cb_data['collector'] = collector def post_cb(result: Iq) -> None: results = cb_data['collector'].stop() if result['type'] == 'result': result['mam']['results'] = results result['mam_fin']['results'] = results if iterator: return self.xmpp['xep_0059'].iterate(iq, 'mam', 'results', amount=amount, reverse=reverse, recv_interface='mam_fin', pre_cb=pre_cb, post_cb=post_cb) collector = Collector('MAM_Results_%s' % query_id, MatchXMLMask(xml_mask)) self.xmpp.register_handler(collector) def wrapped_cb(iq: Iq) -> None: results = collector.stop() if iq['type'] == 'result': iq['mam']['results'] = results if callback: callback(iq) return iq.send(timeout=timeout, callback=wrapped_cb)