comparison src/plugins/plugin_xep_0277.py @ 2360:72cbb6478f97

plugin XEP-0060: use client instead of profile_key in getItems
author Goffi <goffi@goffi.org>
date Sun, 24 Sep 2017 16:32:22 +0200
parents f9580b4a105a
children f57a8eaec8ed
comparison
equal deleted inserted replaced
2359:47516e90d26a 2360:72cbb6478f97
628 628
629 @return: a deferred couple with the list of items and metadatas. 629 @return: a deferred couple with the list of items and metadatas.
630 """ 630 """
631 if node is None: 631 if node is None:
632 node = NS_MICROBLOG 632 node = NS_MICROBLOG
633 items_data = yield self._p.getItems(service, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=client.profile) 633 items_data = yield self._p.getItems(client, service, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra)
634 serialised = yield self._p.serItemsDataD(items_data, self.item2mbdata) 634 serialised = yield self._p.serItemsDataD(items_data, self.item2mbdata)
635 defer.returnValue(serialised) 635 defer.returnValue(serialised)
636 636
637 def parseCommentUrl(self, node_url): 637 def parseCommentUrl(self, node_url):
638 """Parse a XMPP URI 638 """Parse a XMPP URI
890 """ 890 """
891 # XXX: this method seems complicated because it do a couple of treatments 891 # XXX: this method seems complicated because it do a couple of treatments
892 # to serialise and associate the data, but it make life in frontends side 892 # to serialise and associate the data, but it make life in frontends side
893 # a lot easier 893 # a lot easier
894 894
895 client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key)
896
895 def getComments(items_data): 897 def getComments(items_data):
896 """Retrieve comments and add them to the items_data 898 """Retrieve comments and add them to the items_data
897 899
898 @param items_data: serialised items data 900 @param items_data: serialised items data
899 @return (defer.Deferred): list of items where each item is associated 901 @return (defer.Deferred): list of items where each item is associated
908 if key.startswith('comments') and key.endswith('_service'): 910 if key.startswith('comments') and key.endswith('_service'):
909 prefix = key[:key.find('_')] 911 prefix = key[:key.find('_')]
910 service_s = value 912 service_s = value
911 node = item["{}{}".format(prefix, "_node")] 913 node = item["{}{}".format(prefix, "_node")]
912 # time to get the comments 914 # time to get the comments
913 d = self._p.getItems(jid.JID(service_s), node, max_comments, rsm_request=rsm_comments, extra=extra_comments, profile_key=profile_key) 915 d = self._p.getItems(client, jid.JID(service_s), node, max_comments, rsm_request=rsm_comments, extra=extra_comments)
914 # then serialise 916 # then serialise
915 d.addCallback(lambda items_data: self._p.serItemsDataD(items_data, self.item2mbdata)) 917 d.addCallback(lambda items_data: self._p.serItemsDataD(items_data, self.item2mbdata))
916 # with failure handling 918 # with failure handling
917 d.addCallback(lambda serialised_items_data: ('',) + serialised_items_data) 919 d.addCallback(lambda serialised_items_data: ('',) + serialised_items_data)
918 d.addErrback(lambda failure: (unicode(failure.value), [], {})) 920 d.addErrback(lambda failure: (unicode(failure.value), [], {}))
928 items_d = defer.gatherResults(items_dlist) 930 items_d = defer.gatherResults(items_dlist)
929 # and add the metadata 931 # and add the metadata
930 items_d.addCallback(lambda items_completed: (items_completed, metadata)) 932 items_d.addCallback(lambda items_completed: (items_completed, metadata))
931 return items_d 933 return items_d
932 934
933 client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key)
934 deferreds = {} 935 deferreds = {}
935 for service, node in node_data: 936 for service, node in node_data:
936 d = deferreds[(service, node)] = self._p.getItems(service, node, max_items, rsm_request=rsm_request, extra=extra, profile_key=profile_key) 937 d = deferreds[(service, node)] = self._p.getItems(client, service, node, max_items, rsm_request=rsm_request, extra=extra)
937 d.addCallback(lambda items_data: self._p.serItemsDataD(items_data, self.item2mbdata)) 938 d.addCallback(lambda items_data: self._p.serItemsDataD(items_data, self.item2mbdata))
938 d.addCallback(getComments) 939 d.addCallback(getComments)
939 d.addCallback(lambda items_comments_data: ('', items_comments_data)) 940 d.addCallback(lambda items_comments_data: ('', items_comments_data))
940 d.addErrback(lambda failure: (unicode(failure.value), ([],{}))) 941 d.addErrback(lambda failure: (unicode(failure.value), ([],{})))
941 942