comparison src/plugins/plugin_xep_0277.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 e8c8e467964b
children 9b88b19b1ca8
comparison
equal deleted inserted replaced
1449:389357fd79ce 1450:7797dda847ae
71 'param_1': 'max_items: see XEP-0060 #6.5.7', 71 'param_1': 'max_items: see XEP-0060 #6.5.7',
72 'param_2': '%(doc_profile)s', 72 'param_2': '%(doc_profile)s',
73 'return': 'list of microblog data (dict)'}) 73 'return': 'list of microblog data (dict)'})
74 host.bridge.addMethod("setMicroblogAccess", ".plugin", in_sign='ss', out_sign='', 74 host.bridge.addMethod("setMicroblogAccess", ".plugin", in_sign='ss', out_sign='',
75 method=self.setMicroblogAccess, 75 method=self.setMicroblogAccess,
76 async=True, 76 async=True)
77 doc={}) 77 host.bridge.addMethod("mBSubscribeToMany", ".plugin", in_sign='sass', out_sign='s',
78 method=self._mBSubscribeToMany)
78 79
79 ## plugin management methods ## 80 ## plugin management methods ##
80 81
81 def microblogCB(self, itemsEvent, profile): 82 def microblogCB(self, itemsEvent, profile):
82 """Callback to "MICROBLOG" PEP event.""" 83 """Callback to "MICROBLOG" PEP event."""
399 400
400 def change_node_options(): 401 def change_node_options():
401 return self.host.plugins["XEP-0060"].setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key) 402 return self.host.plugins["XEP-0060"].setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key)
402 403
403 create_node().addCallback(cb).addErrback(err_cb) 404 create_node().addCallback(cb).addErrback(err_cb)
405
406 ## methods to manage several stanzas/jids at once ##
407
408 # common
409
410 def _getClientAndNodeData(self, publishers_type, publishers, profile_key):
411 """Helper method to construct node_data from publishers_type/publishers
412
413 @param publishers_type: type of the list of publishers, one of:
414 C.ALL: get all jids from roster, publishers is not used
415 C.GROUP: get jids from groups
416 C.JID: use publishers directly as list of jids
417 @param publishers: list of publishers, according to "publishers_type" (None, list of groups or list of jids)
418 @param profile_key: %(doc_profile_key)s
419 """
420 client = self.host.getClient(profile_key)
421 if publishers_type == C.JID:
422 jids_set = set(publishers)
423 else:
424 jids_set = client.roster.getJidsSet(publishers_type, publishers)
425
426 node_data = []
427 for jid_ in jids_set:
428 node_data.append((jid_, NS_MICROBLOG))
429 return client, node_data
430
431 def _checkPublishers(self, publishers_type, publishers):
432 """Helper method to deserialise publishers coming from bridge
433
434 publishers_type(unicode): type of the list of publishers, one of:
435 publishers: list of publishers according to type
436 @return: deserialised (publishers_type, publishers) tuple
437 """
438 if publishers_type == C.ALL:
439 if publishers:
440 raise failure.Failure(ValueError("Can't use publishers with {} type".format(publishers_type)))
441 else:
442 publishers = None
443 elif publishers_type == C.JID:
444 publishers[:] = [jid.JID(publisher) for publisher in publishers]
445 return publishers_type, publishers
446
447 # subscribe #
448
449 def _mBSubscribeToMany(self, publishers_type, publishers, profile_key):
450 """
451
452 @return (str): session id: Use pubsub.getSubscribeRTResult to get the results
453 """
454 publishers_type, publishers = self._checkPublishers(publishers_type, publishers)
455 return self.mBSubscribeToMany(publishers_type, publishers, profile_key)
456
457 def mBSubscribeToMany(self, publishers_type, publishers, profile_key):
458 """Subscribe microblogs for a list of groups or jids
459
460 @param publishers_type: type of the list of publishers, one of:
461 C.ALL: get all jids from roster, publishers is not used
462 C.GROUP: get jids from groups
463 C.JID: use publishers directly as list of jids
464 @param publishers: list of publishers, according to "publishers_type" (None, list of groups or list of jids)
465 @param profile: %(doc_profile)s
466 @return (str): session id
467 """
468 client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key)
469 return self.host.plugins["XEP-0060"].subscribeToMany(node_data, client.jid.userhostJID(), profile_key=profile_key)
470