plugin group blog: management of extra data/rich text for blog comments
This commit is contained in:
parent
d6e7ec0055
commit
a2a0f43450
1 changed files with 27 additions and 23 deletions
|
|
@ -20,9 +20,8 @@
|
|||
from logging import debug, info, warning, error
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
|
||||
from sat.core import exceptions
|
||||
from wokkel import disco, data_form, iwokkel
|
||||
|
||||
from zope.interface import implements
|
||||
|
||||
import uuid
|
||||
|
|
@ -88,7 +87,7 @@ class GroupBlog(object):
|
|||
method=self.sendGroupBlog,
|
||||
async=True)
|
||||
|
||||
host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='sss', out_sign='',
|
||||
host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='ssa{ss}s', out_sign='',
|
||||
method=self.sendGroupBlogComment,
|
||||
async=True)
|
||||
|
||||
|
|
@ -121,14 +120,13 @@ class GroupBlog(object):
|
|||
return GroupBlog_handler()
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def initialise(self, profile_key):
|
||||
def _initialise(self, profile_key):
|
||||
"""Check that this data for this profile are initialised, and do it else
|
||||
@param client: client of the profile
|
||||
@profile_key: %(doc_profile)s"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_("Unknown profile"))
|
||||
raise Exception("Unknown profile")
|
||||
raise exceptions.ProfileUnknownError
|
||||
|
||||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
|
|
@ -328,7 +326,7 @@ class GroupBlog(object):
|
|||
@param extra: dict which option name as key, which can be:
|
||||
- allow_comments: True to accept comments, False else (default: False)
|
||||
- rich: if present, contain rich text in currently selected syntax
|
||||
@profile_key: %(doc_profile)s
|
||||
@profile_key: %(doc_profile_key)s
|
||||
"""
|
||||
|
||||
def initialised(result):
|
||||
|
|
@ -348,25 +346,31 @@ class GroupBlog(object):
|
|||
error(_("Unknown access type"))
|
||||
raise BadAccessTypeError
|
||||
|
||||
return self.initialise(profile_key).addCallback(initialised)
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
|
||||
def sendGroupBlogComment(self, node_url, message, profile_key='@NONE@'):
|
||||
def sendGroupBlogComment(self, node_url, message, extra, profile_key='@NONE@'):
|
||||
"""Publish a comment in the given node
|
||||
@param node url: link to the comments node as specified in XEP-0277 and given in microblog data's comments key
|
||||
@param message: comment
|
||||
@param extra: dict which option name as key, which can be:
|
||||
- allow_comments: True to accept an other level of comments, False else (default: False)
|
||||
- rich: if present, contain rich text in currently selected syntax
|
||||
@profile_key: %(doc_profile)s
|
||||
"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_("Unknown profile"))
|
||||
raise Exception("Unknown profile")
|
||||
def initialised(result):
|
||||
profile, client = result
|
||||
service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url)
|
||||
mblog_data = {'content': message}
|
||||
if 'rich' in extra:
|
||||
mblog_data['rich'] = extra['rich']
|
||||
if 'allow_comments' in extra:
|
||||
raise NotImplementedError # TODO
|
||||
entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)
|
||||
entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile))
|
||||
return entry_d
|
||||
|
||||
service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url)
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
|
||||
mblog_data = {'content': message}
|
||||
entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)
|
||||
entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile))
|
||||
return entry_d
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _itemsConstruction(self, items, pub_jid, client):
|
||||
|
|
@ -409,7 +413,7 @@ class GroupBlog(object):
|
|||
return d
|
||||
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
return self.initialise(profile_key).addCallback(initialised)
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
|
||||
def getGroupBlogComments(self, service_s, node, profile_key='@NONE@'):
|
||||
"""Get all comments of given node
|
||||
|
|
@ -429,7 +433,7 @@ class GroupBlog(object):
|
|||
return d
|
||||
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
return self.initialise(profile_key).addCallback(initialised)
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
|
||||
def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'):
|
||||
"""Get the last published microblogs for a list of groups or jids
|
||||
|
|
@ -487,7 +491,7 @@ class GroupBlog(object):
|
|||
raise Exception("Bad call, unknown publishers_type")
|
||||
if publishers_type == "ALL" and publishers:
|
||||
raise Exception("Publishers list must be empty when getting microblogs for all contacts")
|
||||
return self.initialise(profile_key).addCallback(initialised)
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
|
||||
def subscribeGroupBlog(self, pub_jid, profile_key='@NONE@'):
|
||||
|
|
@ -498,7 +502,7 @@ class GroupBlog(object):
|
|||
return d
|
||||
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
return self.initialise(profile_key).addCallback(initialised)
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
|
||||
def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'):
|
||||
"""Subscribe microblogs for a list of groups or jids
|
||||
|
|
@ -535,7 +539,7 @@ class GroupBlog(object):
|
|||
raise Exception("Bad call, unknown publishers_type")
|
||||
if publishers_type == "ALL" and publishers:
|
||||
raise Exception("Publishers list must be empty when getting microblogs for all contacts")
|
||||
return self.initialise(profile_key).addCallback(initialised)
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue