Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0060.py @ 2758:f4070693814a
plugin XEP-0060: fixed MAM return value on getItems():
callback to generate metadata was using wrong items in return argument.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 06 Jan 2019 17:33:53 +0100 |
parents | bb6adaa580ee |
children | 3480d4fdf83a |
comparison
equal
deleted
inserted
replaced
2757:1f612547fb2e | 2758:f4070693814a |
---|---|
514 """Retrieve pubsub items from a node. | 514 """Retrieve pubsub items from a node. |
515 | 515 |
516 @param service (JID, None): pubsub service. | 516 @param service (JID, None): pubsub service. |
517 @param node (str): node id. | 517 @param node (str): node id. |
518 @param max_items (int): optional limit on the number of retrieved items. | 518 @param max_items (int): optional limit on the number of retrieved items. |
519 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be used with rsm_request). | 519 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be |
520 used with rsm_request). | |
520 @param sub_id (str): optional subscription identifier. | 521 @param sub_id (str): optional subscription identifier. |
521 @param rsm_request (rsm.RSMRequest): RSM request data | 522 @param rsm_request (rsm.RSMRequest): RSM request data |
522 @return: a deferred couple (list[dict], dict) containing: | 523 @return: a deferred couple (list[dict], dict) containing: |
523 - list of items | 524 - list of items |
524 - metadata with the following keys: | 525 - metadata with the following keys: |
536 mam_query = extra["mam"] | 537 mam_query = extra["mam"] |
537 except KeyError: | 538 except KeyError: |
538 d = client.pubsub_client.items( | 539 d = client.pubsub_client.items( |
539 service, node, max_items, item_ids, sub_id, None, rsm_request | 540 service, node, max_items, item_ids, sub_id, None, rsm_request |
540 ) | 541 ) |
542 # we have no MAM data here, so we add None | |
543 d.addCallback(lambda data: data + (None,)) | |
541 else: | 544 else: |
542 # if mam is requested, we have to do a totally different query | 545 # if mam is requested, we have to do a totally different query |
543 if self._mam is None: | 546 if self._mam is None: |
544 raise exceptions.NotFound(u"MAM (XEP-0313) plugin is not available") | 547 raise exceptions.NotFound(u"MAM (XEP-0313) plugin is not available") |
545 if max_items is not None: | 548 if max_items is not None: |
558 if mam_query.rsm != rsm_request: | 561 if mam_query.rsm != rsm_request: |
559 raise exceptions.DataError( | 562 raise exceptions.DataError( |
560 u"Conflict between RSM request and MAM's RSM request" | 563 u"Conflict between RSM request and MAM's RSM request" |
561 ) | 564 ) |
562 d = self._mam.getArchives(client, mam_query, service, self._unwrapMAMMessage) | 565 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]) | |
565 | 566 |
566 try: | 567 try: |
567 subscribe = C.bool(extra["subscribe"]) | 568 subscribe = C.bool(extra["subscribe"]) |
568 except KeyError: | 569 except KeyError: |
569 subscribe = False | 570 subscribe = False |
584 | 585 |
585 if subscribe: | 586 if subscribe: |
586 d.addCallback(doSubscribe) | 587 d.addCallback(doSubscribe) |
587 | 588 |
588 def addMetadata(result): | 589 def addMetadata(result): |
589 items, rsm_response = result | 590 # TODO: handle the third argument (mam_response) |
591 items, rsm_response, mam_response = result | |
590 service_jid = service if service else client.jid.userhostJID() | 592 service_jid = service if service else client.jid.userhostJID() |
591 metadata = { | 593 metadata = { |
592 "service": service_jid, | 594 "service": service_jid, |
593 "node": node, | 595 "node": node, |
594 "uri": self.getNodeURI(service_jid, node), | 596 "uri": self.getNodeURI(service_jid, node), |
595 } | 597 } |
596 if rsm_request is not None and rsm_response is not None: | 598 if rsm_request is not None and rsm_response is not None: |
597 metadata.update( | 599 metadata.update( |
598 { | 600 { |
599 "rsm_{}".format(key): value | 601 u"rsm_" + key: value |
600 for key, value in rsm_response.toDict().iteritems() | 602 for key, value in rsm_response.toDict().iteritems() |
601 } | 603 } |
602 ) | 604 ) |
605 if mam_response is not None: | |
606 for key, value in mam_response.iteritems(): | |
607 metadata[u"mam_" + key] = value | |
603 return (items, metadata) | 608 return (items, metadata) |
604 | 609 |
605 d.addCallback(addMetadata) | 610 d.addCallback(addMetadata) |
606 return d | 611 return d |
607 | 612 |