comparison src/plugins/plugin_misc_groupblog.py @ 703:0c2c1dfb79e4

plugin group blog: renamed options parameter as extra for consistency with sendMessage
author Goffi <goffi@goffi.org>
date Thu, 14 Nov 2013 16:49:57 +0100
parents 69a8bfd266a5
children 3c304929af74
comparison
equal deleted inserted replaced
702:a25db3fe3959 703:0c2c1dfb79e4
238 """Retrieve the name of publisher's node 238 """Retrieve the name of publisher's node
239 @param publisher: publisher's jid 239 @param publisher: publisher's jid
240 @return: node's name (string)""" 240 @return: node's name (string)"""
241 return NS_NODE_PREFIX + publisher.userhost() 241 return NS_NODE_PREFIX + publisher.userhost()
242 242
243 def _publishMblog(self, service, client, access_type, access_list, message, options): 243 def _publishMblog(self, service, client, access_type, access_list, message, extra):
244 """Actually publish the message on the group blog 244 """Actually publish the message on the group blog
245 @param service: jid of the item-access pubsub service 245 @param service: jid of the item-access pubsub service
246 @param client: SatXMPPClient of the published 246 @param client: SatXMPPClient of the published
247 @param access_type: one of "PUBLIC", "GROUP", "JID" 247 @param access_type: one of "PUBLIC", "GROUP", "JID"
248 @param access_list: set of entities (empty list for all, groups or jids) allowed to see the item 248 @param access_list: set of entities (empty list for all, groups or jids) allowed to see the item
249 @param message: message to publish 249 @param message: message to publish
250 @param options: dict which option name as key, which can be: 250 @param extra: dict which option name as key, which can be:
251 - allow_comments: True to accept comments, False else (default: False) 251 - allow_comments: True to accept comments, False else (default: False)
252 """ 252 """
253 node_name = self.getNodeName(client.jid) 253 node_name = self.getNodeName(client.jid)
254 mblog_data = {'content': message} 254 mblog_data = {'content': message}
255 P = self.host.plugins["XEP-0060"] 255 P = self.host.plugins["XEP-0060"]
256 access_model_value = ACCESS_TYPE_MAP[access_type] 256 access_model_value = ACCESS_TYPE_MAP[access_type]
257 257
258 if options.get('allow_comments', 'False').lower() == 'true': 258 if extra.get('allow_comments', 'False').lower() == 'true':
259 comments_node = "%s_%s__%s" % (NS_COMMENT_PREFIX, str(uuid.uuid4()), node_name) 259 comments_node = "%s_%s__%s" % (NS_COMMENT_PREFIX, str(uuid.uuid4()), node_name)
260 mblog_data['comments'] = "xmpp:%(service)s?%(query)s" % {'service': service.userhost(), 260 mblog_data['comments'] = "xmpp:%(service)s?%(query)s" % {'service': service.userhost(),
261 'query': urllib.urlencode([('node',comments_node.encode('utf-8'))])} 261 'query': urllib.urlencode([('node',comments_node.encode('utf-8'))])}
262 _options = {P.OPT_ACCESS_MODEL: access_model_value, 262 _options = {P.OPT_ACCESS_MODEL: access_model_value,
263 P.OPT_PERSIST_ITEMS: 1, 263 P.OPT_PERSIST_ITEMS: 1,
299 299
300 def _mblogPublicationFailed(self, failure): 300 def _mblogPublicationFailed(self, failure):
301 #TODO 301 #TODO
302 return failure 302 return failure
303 303
304 def sendGroupBlog(self, access_type, access_list, message, options, profile_key='@NONE@'): 304 def sendGroupBlog(self, access_type, access_list, message, extra, profile_key='@NONE@'):
305 """Publish a microblog with given item access 305 """Publish a microblog with given item access
306 @param access_type: one of "PUBLIC", "GROUP", "JID" 306 @param access_type: one of "PUBLIC", "GROUP", "JID"
307 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS, 307 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS,
308 list of groups or list of jids) for this item 308 list of groups or list of jids) for this item
309 @param message: microblog 309 @param message: microblog
310 @param options: dict which option name as key, which can be: 310 @param extra: dict which option name as key, which can be:
311 - allow_comments: True to accept comments, False else (default: False) 311 - allow_comments: True to accept comments, False else (default: False)
312 @profile_key: %(doc_profile)s 312 @profile_key: %(doc_profile)s
313 """ 313 """
314 314
315 def initialised(result): 315 def initialised(result):
316 profile, client = result 316 profile, client = result
317 if access_type == "PUBLIC": 317 if access_type == "PUBLIC":
318 if access_list: 318 if access_list:
319 raise Exception("Publishers list must be empty when getting microblogs for all contacts") 319 raise Exception("Publishers list must be empty when getting microblogs for all contacts")
320 self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, options) 320 self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, extra)
321 elif access_type == "GROUP": 321 elif access_type == "GROUP":
322 _groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist 322 _groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist
323 if not _groups: 323 if not _groups:
324 raise BadAccessListError("No valid group") 324 raise BadAccessListError("No valid group")
325 self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, options) 325 self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, extra)
326 elif access_type == "JID": 326 elif access_type == "JID":
327 raise NotImplementedError 327 raise NotImplementedError
328 else: 328 else:
329 error(_("Unknown access type")) 329 error(_("Unknown access type"))
330 raise BadAccessTypeError 330 raise BadAccessTypeError