Mercurial > libervia-backend
comparison src/plugins/plugin_misc_groupblog.py @ 704:3c304929af74
plugin XEP-0277, group blogs: proper asynchronous methods for sending blogs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 14 Nov 2013 17:51:35 +0100 |
parents | 0c2c1dfb79e4 |
children | 80e9d3ecb272 |
comparison
equal
deleted
inserted
replaced
703:0c2c1dfb79e4 | 704:3c304929af74 |
---|---|
83 def __init__(self, host): | 83 def __init__(self, host): |
84 info(_("Group blog plugin initialization")) | 84 info(_("Group blog plugin initialization")) |
85 self.host = host | 85 self.host = host |
86 | 86 |
87 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sassa{ss}s', out_sign='', | 87 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sassa{ss}s', out_sign='', |
88 method=self.sendGroupBlog) | 88 method=self.sendGroupBlog, |
89 async=True) | |
89 | 90 |
90 host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='sss', out_sign='', | 91 host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='sss', out_sign='', |
91 method=self.sendGroupBlogComment, | 92 method=self.sendGroupBlogComment, |
92 async=True) | 93 async=True) |
93 | 94 |
294 error(_("Unknown access_type")) | 295 error(_("Unknown access_type")) |
295 raise BadAccessTypeError | 296 raise BadAccessTypeError |
296 | 297 |
297 defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile) | 298 defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile) |
298 defer_blog.addErrback(self._mblogPublicationFailed) | 299 defer_blog.addErrback(self._mblogPublicationFailed) |
300 return defer_blog | |
299 | 301 |
300 def _mblogPublicationFailed(self, failure): | 302 def _mblogPublicationFailed(self, failure): |
301 #TODO | 303 #TODO |
302 return failure | 304 return failure |
303 | 305 |
315 def initialised(result): | 317 def initialised(result): |
316 profile, client = result | 318 profile, client = result |
317 if access_type == "PUBLIC": | 319 if access_type == "PUBLIC": |
318 if access_list: | 320 if access_list: |
319 raise Exception("Publishers list must be empty when getting microblogs for all contacts") | 321 raise Exception("Publishers list must be empty when getting microblogs for all contacts") |
320 self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, extra) | 322 return self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, extra) |
321 elif access_type == "GROUP": | 323 elif access_type == "GROUP": |
322 _groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist | 324 _groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist |
323 if not _groups: | 325 if not _groups: |
324 raise BadAccessListError("No valid group") | 326 raise BadAccessListError("No valid group") |
325 self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, extra) | 327 return self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, extra) |
326 elif access_type == "JID": | 328 elif access_type == "JID": |
327 raise NotImplementedError | 329 raise NotImplementedError |
328 else: | 330 else: |
329 error(_("Unknown access type")) | 331 error(_("Unknown access type")) |
330 raise BadAccessTypeError | 332 raise BadAccessTypeError |
331 | 333 |
332 self.initialise(profile_key).addCallback(initialised) | 334 return self.initialise(profile_key).addCallback(initialised) |
333 | 335 |
334 def sendGroupBlogComment(self, node_url, message, profile_key='@NONE@'): | 336 def sendGroupBlogComment(self, node_url, message, profile_key='@NONE@'): |
335 """Publish a comment in the given node | 337 """Publish a comment in the given node |
336 @param node url: link to the comments node as specified in XEP-0277 and given in microblog data's comments key | 338 @param node url: link to the comments node as specified in XEP-0277 and given in microblog data's comments key |
337 @param message: comment | 339 @param message: comment |