comparison src/plugins/plugin_misc_groupblog.py @ 726:ade9997fabfa

core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
author Goffi <goffi@goffi.org>
date Tue, 10 Dec 2013 17:25:31 +0100
parents 6aa71c853bf5
children 80c1072390f3
comparison
equal deleted inserted replaced
725:7c806491c76a 726:ade9997fabfa
96 method=self.getLastGroupBlogs, 96 method=self.getLastGroupBlogs,
97 async=True) 97 async=True)
98 98
99 host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin", 99 host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin",
100 in_sign='sasis', out_sign='a{saa{ss}}', 100 in_sign='sasis', out_sign='a{saa{ss}}',
101 method=self.getMassiveLastGroupBlogs, 101 method=self._getMassiveLastGroupBlogs,
102 async=True) 102 async=True)
103 103
104 host.bridge.addMethod("getGroupBlogComments", ".plugin", 104 host.bridge.addMethod("getGroupBlogComments", ".plugin",
105 in_sign='sss', out_sign='aa{ss}', 105 in_sign='sss', out_sign='aa{ss}',
106 method=self.getGroupBlogComments, 106 method=self.getGroupBlogComments,
109 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='', 109 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='',
110 method=self.subscribeGroupBlog, 110 method=self.subscribeGroupBlog,
111 async=True) 111 async=True)
112 112
113 host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='', 113 host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='',
114 method=self.massiveSubscribeGroupBlogs, 114 method=self._massiveSubscribeGroupBlogs,
115 async=True) 115 async=True)
116 116
117 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger) 117 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
118 118
119 def getHandler(self, profile): 119 def getHandler(self, profile):
433 return d 433 return d
434 434
435 #TODO: we need to use the server corresponding the the host of the jid 435 #TODO: we need to use the server corresponding the the host of the jid
436 return self._initialise(profile_key).addCallback(initialised) 436 return self._initialise(profile_key).addCallback(initialised)
437 437
438 def _getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'):
439 if publishers_type == 'JID':
440 publishers_jids = [jid.JID(publisher) for publisher in publishers]
441 else:
442 publishers_jid = publishers
443 return getMassiveLastGroupBlogs(publishers_type, publishers_jid, max_items, profile_key)
444
438 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'): 445 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'):
439 """Get the last published microblogs for a list of groups or jids 446 """Get the last published microblogs for a list of groups or jids
440 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") 447 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
441 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) 448 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
442 @param max_items: how many microblogs we want to get 449 @param max_items: how many microblogs we want to get
458 def initialised(result): 465 def initialised(result):
459 profile, client = result 466 profile, client = result
460 467
461 if publishers_type == "ALL": 468 if publishers_type == "ALL":
462 contacts = client.roster.getItems() 469 contacts = client.roster.getItems()
463 jids = [contact.jid.userhost() for contact in contacts] 470 jids = [contact.jid.userhostJID() for contact in contacts]
464 elif publishers_type == "GROUP": 471 elif publishers_type == "GROUP":
465 jids = [] 472 jids = []
466 for _group in publishers: 473 for _group in publishers:
467 jids.extend(client.roster.getJidsFromGroup(_group)) 474 jids.extend(client.roster.getJidsFromGroup(_group))
468 elif publishers_type == 'JID': 475 elif publishers_type == 'JID':
471 raise UnknownType 478 raise UnknownType
472 479
473 mblogs = [] 480 mblogs = []
474 481
475 482
476 for jid_s in jids: 483 for jid_ in jids:
477 _jid = jid.JID(jid_s) 484 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid_),
478 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(_jid),
479 max_items=max_items, profile_key=profile_key) 485 max_items=max_items, profile_key=profile_key)
480 d.addCallback(self._itemsConstruction, _jid, client) 486 d.addCallback(self._itemsConstruction, jid_, client)
481 d.addCallback(lambda gbdata, source_jid: (source_jid, gbdata), jid_s) 487 d.addCallback(lambda gbdata, source_jid: (source_jid, gbdata), jid_.full())
482 488
483 mblogs.append(d) 489 mblogs.append(d)
484 dlist = defer.DeferredList(mblogs) 490 dlist = defer.DeferredList(mblogs)
485 dlist.addCallback(sendResult) 491 dlist.addCallback(sendResult)
486 492
502 return d 508 return d
503 509
504 #TODO: we need to use the server corresponding the the host of the jid 510 #TODO: we need to use the server corresponding the the host of the jid
505 return self._initialise(profile_key).addCallback(initialised) 511 return self._initialise(profile_key).addCallback(initialised)
506 512
513 def _massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'):
514 if publishers_type == 'JID':
515 publishers_jids = [jid.JID(publisher) for publisher in publishers]
516 else:
517 publishers_jid = publishers
518 return massiveSubscribeGroupBlogs(publishers_type, publishers_jid, profile_key)
519
507 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'): 520 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'):
508 """Subscribe microblogs for a list of groups or jids 521 """Subscribe microblogs for a list of groups or jids
509 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") 522 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
510 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) 523 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
511 @param profile_key: profile key 524 @param profile_key: profile key
514 def initialised(result): 527 def initialised(result):
515 profile, client = result 528 profile, client = result
516 529
517 if publishers_type == "ALL": 530 if publishers_type == "ALL":
518 contacts = client.roster.getItems() 531 contacts = client.roster.getItems()
519 jids = [contact.jid.userhost() for contact in contacts] 532 jids = [contact.jid.userhostJID() for contact in contacts]
520 elif publishers_type == "GROUP": 533 elif publishers_type == "GROUP":
521 jids = [] 534 jids = []
522 for _group in publishers: 535 for _group in publishers:
523 jids.extend(client.roster.getJidsFromGroup(_group)) 536 jids.extend(client.roster.getJidsFromGroup(_group))
524 elif publishers_type == 'JID': 537 elif publishers_type == 'JID':
525 jids = publishers 538 jids = publishers
526 else: 539 else:
527 raise UnknownType 540 raise UnknownType
528 541
529 mblogs = [] 542 mblogs = []
530 for _jid in jids: 543 for jid_ in jids:
531 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)), 544 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid_),
532 profile_key=profile_key) 545 profile_key=profile_key)
533 mblogs.append(d) 546 mblogs.append(d)
534 dlist = defer.DeferredList(mblogs) 547 dlist = defer.DeferredList(mblogs)
535 return dlist 548 return dlist
536 549