comparison sat/plugins/plugin_xep_0060.py @ 2718:bb6adaa580ee

plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved: - plugin xep-0313: new serialise method - : getArchives now returns an extra mam_response dict with "complete" and "stable" status - : MAMGet now return a new metadata dict before profile (with serialised RSM and MAM response)
author Goffi <goffi@goffi.org>
date Mon, 10 Dec 2018 20:34:45 +0100
parents 6555e9835ff8
children f4070693814a
comparison
equal deleted inserted replaced
2717:e3f6de6ce320 2718:bb6adaa580ee
473 ) 473 )
474 474
475 def _unwrapMAMMessage(self, message_elt): 475 def _unwrapMAMMessage(self, message_elt):
476 try: 476 try:
477 item_elt = ( 477 item_elt = (
478 message_elt.elements(mam.NS_MAM, "result") 478 message_elt.elements(mam.NS_MAM, "result").next()
479 .next() 479 .elements(C.NS_FORWARD, "forwarded").next()
480 .elements(C.NS_FORWARD, "forwarded") 480 .elements(C.NS_CLIENT, "message").next()
481 .next() 481 .elements("http://jabber.org/protocol/pubsub#event", "event").next()
482 .elements(C.NS_CLIENT, "message") 482 .elements("http://jabber.org/protocol/pubsub#event", "items").next()
483 .next() 483 .elements("http://jabber.org/protocol/pubsub#event", "item").next()
484 .elements("http://jabber.org/protocol/pubsub#event", "event")
485 .next()
486 .elements("http://jabber.org/protocol/pubsub#event", "items")
487 .next()
488 .elements("http://jabber.org/protocol/pubsub#event", "item")
489 .next()
490 ) 484 )
491 except StopIteration: 485 except StopIteration:
492 raise exceptions.DataError(u"Can't find Item in MAM message element") 486 raise exceptions.DataError(u"Can't find Item in MAM message element")
493 return item_elt 487 return item_elt
494 488
526 @param sub_id (str): optional subscription identifier. 520 @param sub_id (str): optional subscription identifier.
527 @param rsm_request (rsm.RSMRequest): RSM request data 521 @param rsm_request (rsm.RSMRequest): RSM request data
528 @return: a deferred couple (list[dict], dict) containing: 522 @return: a deferred couple (list[dict], dict) containing:
529 - list of items 523 - list of items
530 - metadata with the following keys: 524 - metadata with the following keys:
531 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index value of RSMResponse 525 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index
526 value of RSMResponse
532 - service, node: service and node used 527 - service, node: service and node used
533 """ 528 """
534 if item_ids and max_items is not None: 529 if item_ids and max_items is not None:
535 max_items = None 530 max_items = None
536 if rsm_request and item_ids: 531 if rsm_request and item_ids:
563 if mam_query.rsm != rsm_request: 558 if mam_query.rsm != rsm_request:
564 raise exceptions.DataError( 559 raise exceptions.DataError(
565 u"Conflict between RSM request and MAM's RSM request" 560 u"Conflict between RSM request and MAM's RSM request"
566 ) 561 )
567 d = self._mam.getArchives(client, mam_query, service, self._unwrapMAMMessage) 562 d = self._mam.getArchives(client, mam_query, service, self._unwrapMAMMessage)
563 # FIXME: we only keep items for now, but RSM and MAM metadata should be used
564 d.addCallback(lambda archives: archives[0])
568 565
569 try: 566 try:
570 subscribe = C.bool(extra["subscribe"]) 567 subscribe = C.bool(extra["subscribe"])
571 except KeyError: 568 except KeyError:
572 subscribe = False 569 subscribe = False