plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
This commit is contained in:
parent
45c81e068b
commit
1e21730bfe
1 changed files with 183 additions and 79 deletions
|
|
@ -108,10 +108,10 @@ class GroupBlog(object):
|
|||
method=self.sendGroupBlogComment,
|
||||
async=True)
|
||||
|
||||
host.bridge.addMethod("getGroupBlogs", ".plugin",
|
||||
in_sign='sasa{ss}bs', out_sign='(aa{ss}a{ss})',
|
||||
method=self.getGroupBlogs,
|
||||
async=True)
|
||||
# host.bridge.addMethod("getGroupBlogs", ".plugin",
|
||||
# in_sign='sasa{ss}bs', out_sign='(aa{ss}a{ss})',
|
||||
# method=self.getGroupBlogs,
|
||||
# async=True)
|
||||
|
||||
host.bridge.addMethod("getGroupBlogsWithComments", ".plugin",
|
||||
in_sign='sasa{ss}is', out_sign='(a(a{ss}(aa{ss}a{ss}))a{ss})',
|
||||
|
|
@ -123,19 +123,19 @@ class GroupBlog(object):
|
|||
method=self.getGroupBlogsAtom,
|
||||
async=True)
|
||||
|
||||
host.bridge.addMethod("getMassiveGroupBlogs", ".plugin",
|
||||
in_sign='sasa{ss}s', out_sign='a{s(aa{ss}a{ss})}',
|
||||
method=self._getMassiveGroupBlogs,
|
||||
async=True)
|
||||
# host.bridge.addMethod("getMassiveGroupBlogs", ".plugin",
|
||||
# in_sign='sasa{ss}s', out_sign='a{s(aa{ss}a{ss})}',
|
||||
# method=self._getMassiveGroupBlogs,
|
||||
# async=True)
|
||||
|
||||
host.bridge.addMethod("getGroupBlogComments", ".plugin",
|
||||
in_sign='ssa{ss}s', out_sign='(aa{ss}a{ss})',
|
||||
method=self.getGroupBlogComments,
|
||||
async=True)
|
||||
# host.bridge.addMethod("getGroupBlogComments", ".plugin",
|
||||
# in_sign='ssa{ss}s', out_sign='(aa{ss}a{ss})',
|
||||
# method=self.getGroupBlogComments,
|
||||
# async=True)
|
||||
|
||||
host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='',
|
||||
method=self.subscribeGroupBlog,
|
||||
async=True)
|
||||
# host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='',
|
||||
# method=self.subscribeGroupBlog,
|
||||
# async=True)
|
||||
|
||||
host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
|
||||
|
||||
|
|
@ -245,6 +245,7 @@ class GroupBlog(object):
|
|||
access_model = form.get(P.OPT_ACCESS_MODEL, 'open')
|
||||
if access_model == "roster":
|
||||
try:
|
||||
# FIXME: groups are xs:string, so they can contain "\n" ! This code is bugged
|
||||
microblog_data["groups"] = '\n'.join(form.fields[P.OPT_ROSTER_GROUPS_ALLOWED].values)
|
||||
except KeyError:
|
||||
log.warning("No group found for roster access-model")
|
||||
|
|
@ -553,22 +554,22 @@ class GroupBlog(object):
|
|||
|
||||
return DeferredItems(self, cb, None, profile_key).get(self.getNodeName(pub_jid), item_ids, rsm_data=rsm_data)
|
||||
|
||||
def getGroupBlogs(self, pub_jid_s, item_ids=None, rsm_data=None, count_comments=True, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get the published microblogs of the specified IDs. If item_ids is
|
||||
None, the result would be the same than calling getGroupBlogs
|
||||
with the default value for the attribute max_items.
|
||||
# def getGroupBlogs(self, pub_jid_s, item_ids=None, rsm_data=None, count_comments=True, profile_key=C.PROF_KEY_NONE):
|
||||
# """Get the published microblogs of the specified IDs. If item_ids is
|
||||
# None, the result would be the same than calling getGroupBlogs
|
||||
# with the default value for the attribute max_items.
|
||||
|
||||
@param pub_jid_s: jid of the publisher
|
||||
@param item_ids: list of microblogs items IDs
|
||||
@param rsm_data (dict): RSM request data
|
||||
@param count_comments (bool): also count the comments if True
|
||||
@param profile_key (str): %(doc_profile_key)s
|
||||
@return: a deferred couple (list, dict) containing:
|
||||
- list of microblog data
|
||||
- RSM response data
|
||||
"""
|
||||
max_comments = 0 if count_comments else DO_NOT_COUNT_COMMENTS
|
||||
return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm_data=rsm_data, max_comments=max_comments, profile_key=profile_key)
|
||||
# @param pub_jid_s: jid of the publisher
|
||||
# @param item_ids: list of microblogs items IDs
|
||||
# @param rsm_data (dict): RSM request data
|
||||
# @param count_comments (bool): also count the comments if True
|
||||
# @param profile_key (str): %(doc_profile_key)s
|
||||
# @return: a deferred couple (list, dict) containing:
|
||||
# - list of microblog data
|
||||
# - RSM response data
|
||||
# """
|
||||
# max_comments = 0 if count_comments else DO_NOT_COUNT_COMMENTS
|
||||
# return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm_data=rsm_data, max_comments=max_comments, profile_key=profile_key)
|
||||
|
||||
def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, rsm_data=None, max_comments=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get the published microblogs of the specified IDs and their comments. If
|
||||
|
|
@ -631,28 +632,12 @@ class GroupBlog(object):
|
|||
d = DeferredItems(self, cb, lambda dummy: [''], profile_key).get(self.getNodeName(pub_jid), rsm_data=rsm_data)
|
||||
return d.addCallback(lambda res: res[0])
|
||||
|
||||
def getGroupBlogComments(self, service_s, node, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get all comments of given node
|
||||
@param service_s: service hosting the node
|
||||
@param node: comments node
|
||||
@param profile_key: profile key
|
||||
@return: a deferred couple (list, dict) containing:
|
||||
- list of microblog data
|
||||
- RSM response data
|
||||
"""
|
||||
service = jid.JID(service_s)
|
||||
|
||||
def cb(items, client):
|
||||
return self._handleCommentsItems(items, service, node)
|
||||
|
||||
return DeferredItems(self, cb, None, profile_key).get(node, rsm_data=rsm_data)
|
||||
|
||||
def _getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
if publishers_type == 'JID':
|
||||
publishers_jids = [jid.JID(publisher) for publisher in publishers]
|
||||
else:
|
||||
publishers_jids = publishers
|
||||
return self.getMassiveGroupBlogs(publishers_type, publishers_jids, rsm_data, profile_key)
|
||||
# def _getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
# if publishers_type == 'JID':
|
||||
# publishers_jids = [jid.JID(publisher) for publisher in publishers]
|
||||
# else:
|
||||
# publishers_jids = publishers
|
||||
# return self.getMassiveGroupBlogs(publishers_type, publishers_jids, rsm_data, profile_key)
|
||||
|
||||
# def _getPublishersJIDs(self, publishers_type, publishers, client):
|
||||
# #TODO: custom exception
|
||||
|
|
@ -674,36 +659,36 @@ class GroupBlog(object):
|
|||
# raise UnknownType
|
||||
# return jids
|
||||
|
||||
def getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get the last published microblogs for a list of groups or jids
|
||||
@param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
|
||||
@param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
|
||||
@param rsm_data (dict): RSM request data, common to all publishers
|
||||
@param profile_key: profile key
|
||||
@return: a deferred dict with:
|
||||
- key: publisher (unicode)
|
||||
- value: couple (list[dict], dict) with:
|
||||
- the microblogs data
|
||||
- RSM response data
|
||||
"""
|
||||
def cb(items, publisher, client):
|
||||
d = self._itemsConstruction(items, publisher, client)
|
||||
return d.addCallback(self._getOrCountComments, False, profile_key)
|
||||
# def getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
# """Get the last published microblogs for a list of groups or jids
|
||||
# @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
|
||||
# @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
|
||||
# @param rsm_data (dict): RSM request data, common to all publishers
|
||||
# @param profile_key: profile key
|
||||
# @return: a deferred dict with:
|
||||
# - key: publisher (unicode)
|
||||
# - value: couple (list[dict], dict) with:
|
||||
# - the microblogs data
|
||||
# - RSM response data
|
||||
# """
|
||||
# def cb(items, publisher, client):
|
||||
# d = self._itemsConstruction(items, publisher, client)
|
||||
# return d.addCallback(self._getOrCountComments, False, profile_key)
|
||||
|
||||
#TODO: we need to use the server corresponding to the host of the jid
|
||||
return DeferredItemsFromMany(self, cb, profile_key).get(publishers_type, publishers, rsm_data=rsm_data)
|
||||
# #TODO: we need to use the server corresponding to the host of the jid
|
||||
# return DeferredItemsFromMany(self, cb, profile_key).get(publishers_type, publishers, rsm_data=rsm_data)
|
||||
|
||||
## subscribe ##
|
||||
|
||||
def subscribeGroupBlog(self, pub_jid, profile_key=C.PROF_KEY_NONE):
|
||||
def initialised(result):
|
||||
profile, client = result
|
||||
d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)),
|
||||
profile_key=profile_key)
|
||||
return d
|
||||
# def subscribeGroupBlog(self, pub_jid, profile_key=C.PROF_KEY_NONE):
|
||||
# def initialised(result):
|
||||
# profile, client = result
|
||||
# d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)),
|
||||
# profile_key=profile_key)
|
||||
# return d
|
||||
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
# #TODO: we need to use the server corresponding the the host of the jid
|
||||
# return self._initialise(profile_key).addCallback(initialised)
|
||||
|
||||
|
||||
## delete ##
|
||||
|
|
|
|||
Loading…
Reference in a new issue