plugin groupblog: added disco info + misc fixes

This commit is contained in:
Goffi 2012-05-31 00:26:39 +02:00
commit 41605b1425

View file

@ -20,19 +20,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
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, pubsub, data_form
from feed.atom import Entry, Author
import uuid
from time import time
from wokkel import disco, data_form, iwokkel
from zope.interface import implements
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 @@ PLUGIN_INFO = {
"protocols": [],
"dependencies": ["XEP-0277"],
"main": "GroupBlog",
"handler": "no",
"handler": "yes",
"description": _("""Implementation of microblogging with roster access""")
}
@ -87,7 +88,9 @@ class GroupBlog():
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 @@ class GroupBlog():
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 @@ class GroupBlog():
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 @@ class GroupBlog():
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 @@ class GroupBlog():
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 []