comparison src/plugins/plugin_misc_groupblog.py @ 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 4c4f88d7b156
children 6ec2741b7268
comparison
equal deleted inserted replaced
1484:05b821a0ff5a 1485:9fcc16ef163a
40 NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog' 40 NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog'
41 NS_NODE_PREFIX = 'urn:xmpp:groupblog:' 41 NS_NODE_PREFIX = 'urn:xmpp:groupblog:'
42 #NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features 42 #NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features
43 NS_PUBSUB_EXP = NS_PUBSUB # XXX: we can't use custom namespace as Wokkel's PubSubService use official NS 43 NS_PUBSUB_EXP = NS_PUBSUB # XXX: we can't use custom namespace as Wokkel's PubSubService use official NS
44 NS_PUBSUB_ITEM_ACCESS = NS_PUBSUB_EXP + "#item-access" 44 NS_PUBSUB_ITEM_ACCESS = NS_PUBSUB_EXP + "#item-access"
45 NS_PUBSUB_GROUPBLOG = NS_PUBSUB_EXP + "#groupblog"
45 NS_PUBSUB_CREATOR_JID_CHECK = NS_PUBSUB_EXP + "#creator-jid-check" 46 NS_PUBSUB_CREATOR_JID_CHECK = NS_PUBSUB_EXP + "#creator-jid-check"
46 NS_PUBSUB_ITEM_CONFIG = NS_PUBSUB_EXP + "#item-config" 47 NS_PUBSUB_ITEM_CONFIG = NS_PUBSUB_EXP + "#item-config"
47 NS_PUBSUB_AUTO_CREATE = NS_PUBSUB + "#auto-create" 48 NS_PUBSUB_AUTO_CREATE = NS_PUBSUB + "#auto-create"
48 TYPE_COLLECTION = 'collection'
49 ACCESS_TYPE_MAP = { 'PUBLIC': 'open', 49 ACCESS_TYPE_MAP = { 'PUBLIC': 'open',
50 'GROUP': 'roster', 50 'GROUP': 'roster',
51 'JID': None, #JID is not yet managed 51 'JID': None, #JID is not yet managed
52 } 52 }
53 53
139 139
140 ## plugin management methods ## 140 ## plugin management methods ##
141 141
142 def getHandler(self, profile): 142 def getHandler(self, profile):
143 return GroupBlog_handler() 143 return GroupBlog_handler()
144
145 @defer.inlineCallbacks
146 def profileConnected(self, profile):
147 client = self.host.getClient(profile)
148 groupblog_services = yield self.host.findFeaturesSet((NS_PUBSUB_GROUPBLOG, NS_PUBSUB_AUTO_CREATE), "pubsub", "service", profile_key=profile)
149 if groupblog_services:
150 # we use one of the found services as our default pubsub service
151 client.groupblog_service = groupblog_services.pop()
152 log.info(_(u"item-access powered pubsub service found: {}").format(client.groupblog_service.full()))
153 else:
154 client.groupblog_service = None
155 log.warning(_(u"No item-access powered pubsub server found, can't use group blog"))
156
157 def getFeatures(self, profile):
158 try:
159 client = self.host.getClient(profile)
160 except exceptions.ProfileNotSetError:
161 return {}
162 try:
163 return {'service': client.groupblog_service.full() if client.groupblog_service is not None else ''}
164 except AttributeError:
165 if self.host.isConnected(profile):
166 log.debug("Profile is not connected, service is not checked yet")
167 else:
168 log.error("Service should be available !")
169 return {}
170
144 171
145 @defer.inlineCallbacks 172 @defer.inlineCallbacks
146 def _initialise(self, profile_key): 173 def _initialise(self, profile_key):
147 """Check that the data for this profile are initialised, and do it else 174 """Check that the data for this profile are initialised, and do it else
148 @param profile_key: %(doc_profile)s""" 175 @param profile_key: %(doc_profile)s"""