plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet

This commit is contained in:
Goffi 2015-08-15 22:20:43 +02:00
commit 2b20bff614

View file

@ -137,9 +137,6 @@ class GroupBlog(object):
method=self.subscribeGroupBlog,
async=True)
host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='',
method=self._massiveSubscribeGroupBlogs,
async=True)
host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
@ -658,25 +655,25 @@ class GroupBlog(object):
publishers_jids = publishers
return self.getMassiveGroupBlogs(publishers_type, publishers_jids, rsm_data, profile_key)
def _getPublishersJIDs(self, publishers_type, publishers, client):
#TODO: custom exception
if publishers_type not in ["GROUP", "JID", "ALL"]:
raise Exception("Bad call, unknown publishers_type")
if publishers_type == "ALL" and publishers:
raise Exception("Publishers list must be empty when getting microblogs for all contacts")
# def _getPublishersJIDs(self, publishers_type, publishers, client):
# #TODO: custom exception
# if publishers_type not in ["GROUP", "JID", "ALL"]:
# raise Exception("Bad call, unknown publishers_type")
# if publishers_type == "ALL" and publishers:
# raise Exception("Publishers list must be empty when getting microblogs for all contacts")
if publishers_type == "ALL":
contacts = client.roster.getItems()
jids = [contact.jid.userhostJID() for contact in contacts]
elif publishers_type == "GROUP":
jids = []
for _group in publishers:
jids.extend(client.roster.getJidsFromGroup(_group))
elif publishers_type == 'JID':
jids = publishers
else:
raise UnknownType
return jids
# if publishers_type == "ALL":
# contacts = client.roster.getItems()
# jids = [contact.jid.userhostJID() for contact in contacts]
# elif publishers_type == "GROUP":
# jids = []
# for _group in publishers:
# jids.extend(client.roster.getJidsFromGroup(_group))
# elif publishers_type == 'JID':
# jids = publishers
# else:
# raise UnknownType
# return jids
def getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
"""Get the last published microblogs for a list of groups or jids
@ -709,28 +706,6 @@ class GroupBlog(object):
#TODO: we need to use the server corresponding the the host of the jid
return self._initialise(profile_key).addCallback(initialised)
def _massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key=C.PROF_KEY_NONE):
if publishers_type == 'JID':
publishers_jids = [jid.JID(publisher) for publisher in publishers]
else:
publishers_jids = publishers
return self.massiveSubscribeGroupBlogs(publishers_type, publishers_jids, profile_key)
@defer.inlineCallbacks
def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key=C.PROF_KEY_NONE):
"""Subscribe microblogs for a list of groups or jids
@param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
@param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
@param profile_key: profile key
"""
profile, client = yield self._initialise(profile_key)
#TODO: we need to use the server corresponding the the host of the jid
jids = self._getPublishersJIDs(publishers_type, publishers, client)
node_ids = [self.getNodeName(publisher) for publisher in jids]
d_list = yield self.host.plugins["XEP-0060"].subscribeToMany(client.item_access_pubsub, node_ids, profile_key=profile_key)
yield defer.DeferredList(d_list, consumeErrors=False)
defer.returnValue(None)
## delete ##