Mercurial > libervia-backend
changeset 1485:9fcc16ef163a
plugin groupblog: groupblog compatible pubsub service is checked in profileConected + getFeatures implementation
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 21 Aug 2015 19:23:14 +0200 |
parents | 05b821a0ff5a |
children | a77217511afd |
files | src/plugins/plugin_misc_groupblog.py |
diffstat | 1 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py Fri Aug 21 19:23:13 2015 +0200 +++ b/src/plugins/plugin_misc_groupblog.py Fri Aug 21 19:23:14 2015 +0200 @@ -42,10 +42,10 @@ #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" +NS_PUBSUB_GROUPBLOG = NS_PUBSUB_EXP + "#groupblog" NS_PUBSUB_CREATOR_JID_CHECK = NS_PUBSUB_EXP + "#creator-jid-check" NS_PUBSUB_ITEM_CONFIG = NS_PUBSUB_EXP + "#item-config" NS_PUBSUB_AUTO_CREATE = NS_PUBSUB + "#auto-create" -TYPE_COLLECTION = 'collection' ACCESS_TYPE_MAP = { 'PUBLIC': 'open', 'GROUP': 'roster', 'JID': None, #JID is not yet managed @@ -143,6 +143,33 @@ return GroupBlog_handler() @defer.inlineCallbacks + def profileConnected(self, profile): + client = self.host.getClient(profile) + groupblog_services = yield self.host.findFeaturesSet((NS_PUBSUB_GROUPBLOG, NS_PUBSUB_AUTO_CREATE), "pubsub", "service", profile_key=profile) + if groupblog_services: + # we use one of the found services as our default pubsub service + client.groupblog_service = groupblog_services.pop() + log.info(_(u"item-access powered pubsub service found: {}").format(client.groupblog_service.full())) + else: + client.groupblog_service = None + log.warning(_(u"No item-access powered pubsub server found, can't use group blog")) + + def getFeatures(self, profile): + try: + client = self.host.getClient(profile) + except exceptions.ProfileNotSetError: + return {} + try: + return {'service': client.groupblog_service.full() if client.groupblog_service is not None else ''} + except AttributeError: + if self.host.isConnected(profile): + log.debug("Profile is not connected, service is not checked yet") + else: + log.error("Service should be available !") + return {} + + + @defer.inlineCallbacks def _initialise(self, profile_key): """Check that the data for this profile are initialised, and do it else @param profile_key: %(doc_profile)s"""