changeset 476:b9fd32b46306

plugin groupblog: added disco info + misc fixes
author Goffi <goffi@goffi.org>
date Thu, 31 May 2012 00:26:39 +0200
parents 6bb9305e0b9c
children 031b0e0aaab8
files src/plugins/plugin_misc_groupblog.py
diffstat 1 files changed, 34 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py	Sat Apr 14 16:26:55 2012 +0200
+++ b/src/plugins/plugin_misc_groupblog.py	Thu May 31 00:26:39 2012 +0200
@@ -20,19 +20,20 @@
 """
 
 from logging import debug, info, error
-from twisted.internet import protocol, defer
+from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
-from twisted.words.protocols.jabber import error as jab_error
-import twisted.internet.error
-from twisted.words.xish import domish
-from sat.tools.xml_tools import ElementParser
+
+from wokkel import disco, data_form, iwokkel
+
+from zope.interface import implements
 
-from wokkel import disco, pubsub, data_form
-from feed.atom import Entry, Author
-import uuid
-from time import time
+try:
+    from twisted.words.protocols.xmlstream import XMPPHandler
+except ImportError:
+    from wokkel.subprotocols import XMPPHandler
 
 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
+NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog'
 #NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features
 NS_PUBSUB_EXP = NS_PUBSUB #XXX: we can't use custom namespace as Wokkel's PubSubService use official NS
 NS_PUBSUB_ITEM_ACCESS = NS_PUBSUB_EXP + "#item-access"
@@ -55,7 +56,7 @@
 "protocols": [],
 "dependencies": ["XEP-0277"],
 "main": "GroupBlog",
-"handler": "no",
+"handler": "yes",
 "description": _("""Implementation of microblogging with roster access""")
 }
 
@@ -87,7 +88,9 @@
                               in_sign='sasis', out_sign='a{saa{ss}}',
                               method=self.getMassiveLastGroupBlogs,
                               async = True)
-                            
+    
+    def getHandler(self, profile):
+        return GroupBlog_handler()
        
     @defer.inlineCallbacks
     def initialise(self, profile_key):
@@ -109,11 +112,10 @@
         if not hasattr(client,"item_access_pubsub"):
             debug(_('Looking for item-access power pubsub server'))
             #we don't have any pubsub server featuring item access yet
-            test = self.host.memory.getServerServiceEntities("pubsub", "service", profile)
             client.item_access_pubsub = None
             for entity in self.host.memory.getServerServiceEntities("pubsub", "service", profile):
-                disco = yield client.disco.requestInfo(entity)
-                if set([NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(disco.features):
+                _disco = yield client.disco.requestInfo(entity)
+                if set([NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features):
                     info(_("item-access powered pubsub service found: [%s]") % entity.full())
                     client.item_access_pubsub = entity
 
@@ -137,9 +139,13 @@
         if access_type == "PUBLIC":
             if access_list:
                 raise BadAccessListError("access_list must be empty for PUBLIC access")
+            access = data_form.Field(None, OPT_ACCESS_MODEL, value="open")
+            form.addField(access)
         elif access_type == "GROUP":
-            field = data_form.Field('list-multi', OPT_ROSTER_GROUPS_ALLOWED, values=access_list)
-            form.addField(field)
+            access = data_form.Field(None, OPT_ACCESS_MODEL, value="roster")
+            allowed = data_form.Field(None, OPT_ROSTER_GROUPS_ALLOWED, values=access_list)
+            form.addField(access)
+            form.addField(allowed)
             mblog_item.addChild(form.toElement())
         elif access_type == "JID":
             raise NotImplementedError
@@ -196,9 +202,11 @@
             d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(),
                                                        max_items=max_items, profile_key=profile_key)
             d.addCallback(lambda items: map(self.host.plugins["XEP-0277"].item2mbdata, items))
+            d.addErrback(lambda ignore: {}) #TODO: more complete error management (log !)
+            return d
 
-        self.initialise(profile_key).addCallback(initialised)
         #TODO: we need to use the server corresponding the the host of the jid
+        return self.initialise(profile_key).addCallback(initialised)
 
     def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@'):
         """Get the last published microblogs for a list of groups or jids
@@ -246,3 +254,12 @@
         return self.initialise(profile_key).addCallback(initialised)
         #TODO: we need to use the server corresponding the the host of the jid
 
+class GroupBlog_handler(XMPPHandler):
+    implements(iwokkel.IDisco)
+    
+    def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
+        return [disco.DiscoFeature(NS_GROUPBLOG)]
+
+    def getDiscoItems(self, requestor, target, nodeIdentifier=''):
+        return []
+