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
2 changed files with 115 additions and 46 deletions

View file

@ -81,6 +81,11 @@ class Const(object):
ENTITY_MAIN_RESOURCE = '@MAIN_RESOURCE@'
ENTITY_CAP_HASH = 'CAP_HASH'
## Roster jids selection ##
ALL = 'ALL'
GROUP = 'GROUP'
JID = 'JID'
## Messages ##
MESS_TYPE_INFO = 'info'

View file

@ -307,6 +307,28 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
except KeyError:
raise exceptions.UnknownGroupError(group)
def getJidsSet(self, type_, groups=None):
"""Helper method to get a set of jids
@param type_(unicode): one of:
C.ALL: get all jids from roster
C.GROUP: get jids from groups (listed in "groups")
@groups(list[unicode]): list of groups used if type_==C.GROUP
@return (set(jid.JID)): set of selected jids
"""
if type_ == C.ALL and groups is not None:
raise ValueError('groups must not be set for {} type'.format(C.ALL))
if type_ == C.ALL:
return set(self.getJids())
elif type_ == C.GROUP:
jids = set()
for group in groups:
jids.update(self.getJidsFromGroup(group))
return jids
else:
raise ValueError(u'Unexpected type_ {}'.format(type_))
class SatPresenceProtocol(xmppim.PresenceClientProtocol):