comparison src/plugins/plugin_misc_groupblog.py @ 529:c18e0e108925

plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
author Goffi <goffi@goffi.org>
date Mon, 22 Oct 2012 00:10:21 +0200
parents 2a072735e459
children db4ae4d18f09
comparison
equal deleted inserted replaced
528:f899f6e2a9d1 529:c18e0e108925
66 66
67 class BadAccessTypeError(Exception): 67 class BadAccessTypeError(Exception):
68 pass 68 pass
69 69
70 class BadAccessListError(Exception): 70 class BadAccessListError(Exception):
71 pass
72
73 class UnknownType(Exception):
71 pass 74 pass
72 75
73 class GroupBlog(): 76 class GroupBlog():
74 """This class use a SàT PubSub Service to manage access on microblog""" 77 """This class use a SàT PubSub Service to manage access on microblog"""
75 78
269 profile, client = result 272 profile, client = result
270 273
271 if publishers_type == "ALL": 274 if publishers_type == "ALL":
272 contacts = client.roster.getItems() 275 contacts = client.roster.getItems()
273 jids = [contact.jid.userhost() for contact in contacts] 276 jids = [contact.jid.userhost() for contact in contacts]
274 mblogs = [] 277 elif publishers_type == "GROUP":
275 for _jid in jids: 278 jids = []
276 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)), 279 for _group in publishers:
277 max_items=max_items, profile_key=profile_key) 280 jids.extend(client.roster.getJidsFromGroup(_group))
278 d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid) 281 elif publishers_type == 'JID':
279 mblogs.append(d) 282 jids = publishers
280 dlist = defer.DeferredList(mblogs) 283 else:
281 dlist.addCallback(sendResult) 284 raise UnknownType
282 return dlist 285
283 286 mblogs = []
284 return defer.fail("Unknown type") 287
288 for _jid in jids:
289 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
290 max_items=max_items, profile_key=profile_key)
291 d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid)
292 mblogs.append(d)
293 dlist = defer.DeferredList(mblogs)
294 dlist.addCallback(sendResult)
295
296 return dlist
285 297
286 298
287 #TODO: custom exception 299 #TODO: custom exception
288 if publishers_type not in ["GROUP", "JID", "ALL"]: 300 if publishers_type not in ["GROUP", "JID", "ALL"]:
289 raise Exception("Bad call, unknown publishers_type") 301 raise Exception("Bad call, unknown publishers_type")
313 profile, client = result 325 profile, client = result
314 326
315 if publishers_type == "ALL": 327 if publishers_type == "ALL":
316 contacts = client.roster.getItems() 328 contacts = client.roster.getItems()
317 jids = [contact.jid.userhost() for contact in contacts] 329 jids = [contact.jid.userhost() for contact in contacts]
318 mblogs = [] 330 elif publishers_type == "GROUP":
319 for _jid in jids: 331 jids = []
320 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)), 332 for _group in publishers:
321 profile_key=profile_key) 333 jids.extend(client.roster.getJidsFromGroup(_group))
322 mblogs.append(d) 334 elif publishers_type == 'JID':
323 dlist = defer.DeferredList(mblogs) 335 jids = publishers
324 return dlist 336 else:
325 337 raise UnknownType
326 return defer.fail("Unknown type") 338
339 mblogs = []
340 for _jid in jids:
341 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
342 profile_key=profile_key)
343 mblogs.append(d)
344 dlist = defer.DeferredList(mblogs)
345 return dlist
327 346
328 347
329 #TODO: custom exception 348 #TODO: custom exception
330 if publishers_type not in ["GROUP", "JID", "ALL"]: 349 if publishers_type not in ["GROUP", "JID", "ALL"]:
331 raise Exception("Bad call, unknown publishers_type") 350 raise Exception("Bad call, unknown publishers_type")