Mercurial > libervia-backend
comparison src/plugins/plugin_misc_groupblog.py @ 1450:7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 15 Aug 2015 22:20:43 +0200 |
parents | 226bbe758b1a |
children | 5116d70ddd1c |
comparison
equal
deleted
inserted
replaced
1449:389357fd79ce | 1450:7797dda847ae |
---|---|
135 | 135 |
136 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='', | 136 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='', |
137 method=self.subscribeGroupBlog, | 137 method=self.subscribeGroupBlog, |
138 async=True) | 138 async=True) |
139 | 139 |
140 host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='', | |
141 method=self._massiveSubscribeGroupBlogs, | |
142 async=True) | |
143 | 140 |
144 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger) | 141 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger) |
145 | 142 |
146 ## plugin management methods ## | 143 ## plugin management methods ## |
147 | 144 |
656 publishers_jids = [jid.JID(publisher) for publisher in publishers] | 653 publishers_jids = [jid.JID(publisher) for publisher in publishers] |
657 else: | 654 else: |
658 publishers_jids = publishers | 655 publishers_jids = publishers |
659 return self.getMassiveGroupBlogs(publishers_type, publishers_jids, rsm_data, profile_key) | 656 return self.getMassiveGroupBlogs(publishers_type, publishers_jids, rsm_data, profile_key) |
660 | 657 |
661 def _getPublishersJIDs(self, publishers_type, publishers, client): | 658 # def _getPublishersJIDs(self, publishers_type, publishers, client): |
662 #TODO: custom exception | 659 # #TODO: custom exception |
663 if publishers_type not in ["GROUP", "JID", "ALL"]: | 660 # if publishers_type not in ["GROUP", "JID", "ALL"]: |
664 raise Exception("Bad call, unknown publishers_type") | 661 # raise Exception("Bad call, unknown publishers_type") |
665 if publishers_type == "ALL" and publishers: | 662 # if publishers_type == "ALL" and publishers: |
666 raise Exception("Publishers list must be empty when getting microblogs for all contacts") | 663 # raise Exception("Publishers list must be empty when getting microblogs for all contacts") |
667 | 664 |
668 if publishers_type == "ALL": | 665 # if publishers_type == "ALL": |
669 contacts = client.roster.getItems() | 666 # contacts = client.roster.getItems() |
670 jids = [contact.jid.userhostJID() for contact in contacts] | 667 # jids = [contact.jid.userhostJID() for contact in contacts] |
671 elif publishers_type == "GROUP": | 668 # elif publishers_type == "GROUP": |
672 jids = [] | 669 # jids = [] |
673 for _group in publishers: | 670 # for _group in publishers: |
674 jids.extend(client.roster.getJidsFromGroup(_group)) | 671 # jids.extend(client.roster.getJidsFromGroup(_group)) |
675 elif publishers_type == 'JID': | 672 # elif publishers_type == 'JID': |
676 jids = publishers | 673 # jids = publishers |
677 else: | 674 # else: |
678 raise UnknownType | 675 # raise UnknownType |
679 return jids | 676 # return jids |
680 | 677 |
681 def getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE): | 678 def getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE): |
682 """Get the last published microblogs for a list of groups or jids | 679 """Get the last published microblogs for a list of groups or jids |
683 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL") | 680 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL") |
684 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids) | 681 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids) |
707 return d | 704 return d |
708 | 705 |
709 #TODO: we need to use the server corresponding the the host of the jid | 706 #TODO: we need to use the server corresponding the the host of the jid |
710 return self._initialise(profile_key).addCallback(initialised) | 707 return self._initialise(profile_key).addCallback(initialised) |
711 | 708 |
712 def _massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key=C.PROF_KEY_NONE): | |
713 if publishers_type == 'JID': | |
714 publishers_jids = [jid.JID(publisher) for publisher in publishers] | |
715 else: | |
716 publishers_jids = publishers | |
717 return self.massiveSubscribeGroupBlogs(publishers_type, publishers_jids, profile_key) | |
718 | |
719 @defer.inlineCallbacks | |
720 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key=C.PROF_KEY_NONE): | |
721 """Subscribe microblogs for a list of groups or jids | |
722 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") | |
723 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) | |
724 @param profile_key: profile key | |
725 """ | |
726 profile, client = yield self._initialise(profile_key) | |
727 #TODO: we need to use the server corresponding the the host of the jid | |
728 | |
729 jids = self._getPublishersJIDs(publishers_type, publishers, client) | |
730 node_ids = [self.getNodeName(publisher) for publisher in jids] | |
731 d_list = yield self.host.plugins["XEP-0060"].subscribeToMany(client.item_access_pubsub, node_ids, profile_key=profile_key) | |
732 yield defer.DeferredList(d_list, consumeErrors=False) | |
733 defer.returnValue(None) | |
734 | 709 |
735 ## delete ## | 710 ## delete ## |
736 | 711 |
737 def deleteGroupBlog(self, pub_data, comments, profile_key=C.PROF_KEY_NONE): | 712 def deleteGroupBlog(self, pub_data, comments, profile_key=C.PROF_KEY_NONE): |
738 """Delete a microblog item from a node. | 713 """Delete a microblog item from a node. |