comparison src/plugins/plugin_misc_groupblog.py @ 1516:afa0894dcc71

plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
author souliane <souliane@mailoo.org>
date Thu, 10 Sep 2015 15:06:01 +0200
parents 6ec2741b7268
children e0bde0d0b321
comparison
equal deleted inserted replaced
1515:30ba7cac1dd2 1516:afa0894dcc71
26 from twisted.words.xish.domish import Element, generateElementsNamed 26 from twisted.words.xish.domish import Element, generateElementsNamed
27 from sat.core import exceptions 27 from sat.core import exceptions
28 from wokkel import disco, data_form, iwokkel 28 from wokkel import disco, data_form, iwokkel
29 from wokkel import rsm 29 from wokkel import rsm
30 from zope.interface import implements 30 from zope.interface import implements
31 from feed import date
32 # import uuid 31 # import uuid
33 32
34 try: 33 try:
35 from twisted.words.protocols.xmlstream import XMPPHandler 34 from twisted.words.protocols.xmlstream import XMPPHandler
36 except ImportError: 35 except ImportError:
112 # async=True) 111 # async=True)
113 112
114 host.bridge.addMethod("getGroupBlogsWithComments", ".plugin", 113 host.bridge.addMethod("getGroupBlogsWithComments", ".plugin",
115 in_sign='sasa{ss}is', out_sign='(a(a{ss}(aa{ss}a{ss}))a{ss})', 114 in_sign='sasa{ss}is', out_sign='(a(a{ss}(aa{ss}a{ss}))a{ss})',
116 method=self.getGroupBlogsWithComments, 115 method=self.getGroupBlogsWithComments,
117 async=True)
118
119 host.bridge.addMethod("getGroupBlogsAtom", ".plugin",
120 in_sign='sa{ss}s', out_sign='s',
121 method=self.getGroupBlogsAtom,
122 async=True) 116 async=True)
123 117
124 # host.bridge.addMethod("getMassiveGroupBlogs", ".plugin", 118 # host.bridge.addMethod("getMassiveGroupBlogs", ".plugin",
125 # in_sign='sasa{ss}s', out_sign='a{s(aa{ss}a{ss})}', 119 # in_sign='sasa{ss}s', out_sign='a{s(aa{ss}a{ss})}',
126 # method=self._getMassiveGroupBlogs, 120 # method=self._getMassiveGroupBlogs,
613 """ 607 """
614 if max_comments is None: 608 if max_comments is None:
615 max_comments = MAX_COMMENTS 609 max_comments = MAX_COMMENTS
616 assert max_comments > 0 # otherwise the return signature is not the same 610 assert max_comments > 0 # otherwise the return signature is not the same
617 return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm_data=rsm_data, max_comments=max_comments, profile_key=profile_key) 611 return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm_data=rsm_data, max_comments=max_comments, profile_key=profile_key)
618
619 def getGroupBlogsAtom(self, pub_jid_s, rsm_data=None, profile_key=C.PROF_KEY_NONE):
620 """Get the atom feed of the last published microblogs
621 @param pub_jid: jid of the publisher
622 @param profile_key: profile key
623 @return: a deferred unicode (atom XML feed)
624 """
625 pub_jid = jid.JID(pub_jid_s)
626
627 def removeAllURIs(element):
628 """Recursively remove the URIs of the element and its children.
629 Without that, the entry would still be valid but not displayed
630 by Firefox nor Thunderbird (and probably more readers)"""
631 element.uri = element.defaultUri = None
632 for child in element.children:
633 if isinstance(child, Element):
634 removeAllURIs(child)
635
636 def items2feed(items, pub_jid, client):
637 feed = """<?xml version="1.0" encoding="utf-8"?>
638 <feed xmlns="http://www.w3.org/2005/Atom">
639 <title>%(user)s's blogposts</title>
640 <link href="%(feed)s" rel="self" />
641 <link href="%(blog)s" />
642 <id>%(id)s</id>
643 <updated>%(date)s</updated>\n""" % {'user': pub_jid.user,
644 'feed': 'http://%s/blog/%s/atom.xml' % (client.jid.host, pub_jid.user),
645 'blog': 'http://%s/blog/%s' % (client.jid.host, pub_jid.user),
646 'id': self.getNodeName(pub_jid),
647 'date': date.rfc3339.timestamp_from_tf(date.rfc3339.tf_utc())}
648 for item in items:
649 entry = item.firstChildElement()
650 removeAllURIs(entry)
651 feed += " " + entry.toXml() + "\n"
652 return feed + "</feed>"
653
654 def cb(items, client):
655 return items2feed(items, pub_jid, client)
656
657 d = DeferredItems(self, cb, lambda dummy: [''], profile_key).get(self.getNodeName(pub_jid), rsm_data=rsm_data)
658 return d.addCallback(lambda res: res[0])
659 612
660 # def _getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE): 613 # def _getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
661 # if publishers_type == 'JID': 614 # if publishers_type == 'JID':
662 # publishers_jids = [jid.JID(publisher) for publisher in publishers] 615 # publishers_jids = [jid.JID(publisher) for publisher in publishers]
663 # else: 616 # else: