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

@ -73,8 +73,9 @@ class XEP_0277(object):
'return': 'list of microblog data (dict)'})
host.bridge.addMethod("setMicroblogAccess", ".plugin", in_sign='ss', out_sign='',
method=self.setMicroblogAccess,
async=True,
doc={})
async=True)
host.bridge.addMethod("mBSubscribeToMany", ".plugin", in_sign='sass', out_sign='s',
method=self._mBSubscribeToMany)
## plugin management methods ##
@ -401,3 +402,69 @@ class XEP_0277(object):
return self.host.plugins["XEP-0060"].setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key)
create_node().addCallback(cb).addErrback(err_cb)
## methods to manage several stanzas/jids at once ##
# common
def _getClientAndNodeData(self, publishers_type, publishers, profile_key):
"""Helper method to construct node_data from publishers_type/publishers
@param publishers_type: type of the list of publishers, one of:
C.ALL: get all jids from roster, publishers is not used
C.GROUP: get jids from groups
C.JID: use publishers directly as list of jids
@param publishers: list of publishers, according to "publishers_type" (None, list of groups or list of jids)
@param profile_key: %(doc_profile_key)s
"""
client = self.host.getClient(profile_key)
if publishers_type == C.JID:
jids_set = set(publishers)
else:
jids_set = client.roster.getJidsSet(publishers_type, publishers)
node_data = []
for jid_ in jids_set:
node_data.append((jid_, NS_MICROBLOG))
return client, node_data
def _checkPublishers(self, publishers_type, publishers):
"""Helper method to deserialise publishers coming from bridge
publishers_type(unicode): type of the list of publishers, one of:
publishers: list of publishers according to type
@return: deserialised (publishers_type, publishers) tuple
"""
if publishers_type == C.ALL:
if publishers:
raise failure.Failure(ValueError("Can't use publishers with {} type".format(publishers_type)))
else:
publishers = None
elif publishers_type == C.JID:
publishers[:] = [jid.JID(publisher) for publisher in publishers]
return publishers_type, publishers
# subscribe #
def _mBSubscribeToMany(self, publishers_type, publishers, profile_key):
"""
@return (str): session id: Use pubsub.getSubscribeRTResult to get the results
"""
publishers_type, publishers = self._checkPublishers(publishers_type, publishers)
return self.mBSubscribeToMany(publishers_type, publishers, profile_key)
def mBSubscribeToMany(self, publishers_type, publishers, profile_key):
"""Subscribe microblogs for a list of groups or jids
@param publishers_type: type of the list of publishers, one of:
C.ALL: get all jids from roster, publishers is not used
C.GROUP: get jids from groups
C.JID: use publishers directly as list of jids
@param publishers: list of publishers, according to "publishers_type" (None, list of groups or list of jids)
@param profile: %(doc_profile)s
@return (str): session id
"""
client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key)
return self.host.plugins["XEP-0060"].subscribeToMany(node_data, client.jid.userhostJID(), profile_key=profile_key)