plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
This commit is contained in:
parent
c831e8f851
commit
dda1628f3d
1 changed files with 71 additions and 50 deletions
|
|
@ -28,7 +28,6 @@ from sat.core import exceptions
|
|||
from wokkel import disco, data_form, iwokkel
|
||||
from wokkel import rsm
|
||||
from zope.interface import implements
|
||||
from feed import date
|
||||
# import uuid
|
||||
|
||||
try:
|
||||
|
|
@ -116,11 +115,6 @@ class GroupBlog(object):
|
|||
method=self.getGroupBlogsWithComments,
|
||||
async=True)
|
||||
|
||||
host.bridge.addMethod("getGroupBlogsAtom", ".plugin",
|
||||
in_sign='sa{ss}s', out_sign='s',
|
||||
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,
|
||||
|
|
@ -616,47 +610,6 @@ class GroupBlog(object):
|
|||
assert max_comments > 0 # otherwise the return signature is not the same
|
||||
return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm_data=rsm_data, max_comments=max_comments, profile_key=profile_key)
|
||||
|
||||
def getGroupBlogsAtom(self, pub_jid_s, rsm_data=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""Get the atom feed of the last published microblogs
|
||||
@param pub_jid: jid of the publisher
|
||||
@param profile_key: profile key
|
||||
@return: a deferred unicode (atom XML feed)
|
||||
"""
|
||||
pub_jid = jid.JID(pub_jid_s)
|
||||
|
||||
def removeAllURIs(element):
|
||||
"""Recursively remove the URIs of the element and its children.
|
||||
Without that, the entry would still be valid but not displayed
|
||||
by Firefox nor Thunderbird (and probably more readers)"""
|
||||
element.uri = element.defaultUri = None
|
||||
for child in element.children:
|
||||
if isinstance(child, Element):
|
||||
removeAllURIs(child)
|
||||
|
||||
def items2feed(items, pub_jid, client):
|
||||
feed = """<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>%(user)s's blogposts</title>
|
||||
<link href="%(feed)s" rel="self" />
|
||||
<link href="%(blog)s" />
|
||||
<id>%(id)s</id>
|
||||
<updated>%(date)s</updated>\n""" % {'user': pub_jid.user,
|
||||
'feed': 'http://%s/blog/%s/atom.xml' % (client.jid.host, pub_jid.user),
|
||||
'blog': 'http://%s/blog/%s' % (client.jid.host, pub_jid.user),
|
||||
'id': self.getNodeName(pub_jid),
|
||||
'date': date.rfc3339.timestamp_from_tf(date.rfc3339.tf_utc())}
|
||||
for item in items:
|
||||
entry = item.firstChildElement()
|
||||
removeAllURIs(entry)
|
||||
feed += " " + entry.toXml() + "\n"
|
||||
return feed + "</feed>"
|
||||
|
||||
def cb(items, client):
|
||||
return items2feed(items, pub_jid, client)
|
||||
|
||||
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 _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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue