diff src/core/xmpp.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 7590bbf44eed
children 8d61160ee4b8
line wrap: on
line diff
--- a/src/core/xmpp.py	Sat Aug 15 22:13:27 2015 +0200
+++ b/src/core/xmpp.py	Sat Aug 15 22:20:43 2015 +0200
@@ -307,6 +307,28 @@
         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):