comparison src/plugins/plugin_xep_0277.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 955221487a3e
children 94901070478e
comparison
equal deleted inserted replaced
1515:30ba7cac1dd2 1516:afa0894dcc71
94 method=self._mbGetFromManyRTResult, async=True) 94 method=self._mbGetFromManyRTResult, async=True)
95 host.bridge.addMethod("mbGetFromMany", ".plugin", in_sign='sasia{ss}s', out_sign='s', 95 host.bridge.addMethod("mbGetFromMany", ".plugin", in_sign='sasia{ss}s', out_sign='s',
96 method=self._mbGetFromMany) 96 method=self._mbGetFromMany)
97 host.bridge.addMethod("mbGetFromManyWithCommentsRTResult", ".plugin", in_sign='ss', out_sign='(ua(sssa(a{ss}a(sssaa{ss}a{ss}))a{ss}))', 97 host.bridge.addMethod("mbGetFromManyWithCommentsRTResult", ".plugin", in_sign='ss', out_sign='(ua(sssa(a{ss}a(sssaa{ss}a{ss}))a{ss}))',
98 method=self._mbGetFromManyWithCommentsRTResult, async=True) 98 method=self._mbGetFromManyWithCommentsRTResult, async=True)
99 host.bridge.addMethod("mbGetFromManyWithComments", ".plugin", in_sign='sasiia{ss}a{ss}s', out_sign='s', method=self._mbGetFromManyWithComments) 99 host.bridge.addMethod("mbGetFromManyWithComments", ".plugin", in_sign='sasiia{ss}a{ss}s', out_sign='s',
100 method=self._mbGetFromManyWithComments)
101 host.bridge.addMethod("mbGetAtom", ".plugin", in_sign='ssiasa{ss}s', out_sign='s',
102 method=self._mbGetAtom, async=True)
100 103
101 ## plugin management methods ## 104 ## plugin management methods ##
102 105
103 def _itemsReceived(self, itemsEvent, profile): 106 def _itemsReceived(self, itemsEvent, profile):
104 """Callback which manage items notifications (publish + retract)""" 107 """Callback which manage items notifications (publish + retract)"""
496 extra = self._p.parseExtra(extra_dict) 499 extra = self._p.parseExtra(extra_dict)
497 return self.mbGet(jid.JID(service_jid_s), node or None, max_items, item_ids, extra.rsm_request, extra.extra, profile_key) 500 return self.mbGet(jid.JID(service_jid_s), node or None, max_items, item_ids, extra.rsm_request, extra.extra, profile_key)
498 501
499 @defer.inlineCallbacks 502 @defer.inlineCallbacks
500 def mbGet(self, service_jid, node=None, max_items=None, item_ids=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): 503 def mbGet(self, service_jid, node=None, max_items=None, item_ids=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE):
501 """Get the last published microblogs 504 """Get some microblogs
502 505
503 @param service_jid(jid.JID): jid of the publisher 506 @param service_jid(jid.JID): jid of the publisher
504 @param node(unicode, None): node to get (or microblog node if None) 507 @param node(unicode, None): node to get (or microblog node if None)
505 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit 508 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
506 @param item_ids (list[unicode]): list of item IDs 509 @param item_ids (list[unicode]): list of item IDs
507 @param rsm_request (rsm.RSMRequest): RSM request data 510 @param rsm_request (rsm.RSMRequest): RSM request data
508 @param profile_key: profile key 511 @param extra (dict): extra data
512 @param profile_key: %(doc_profile_key)s
509 513
510 @return: a deferred couple with the list of items and metadatas. 514 @return: a deferred couple with the list of items and metadatas.
511 """ 515 """
512 if node is None: 516 if node is None:
513 node = NS_MICROBLOG 517 node = NS_MICROBLOG
813 d.addCallback(getComments) 817 d.addCallback(getComments)
814 d.addCallback(lambda items_comments_data: ('', items_comments_data)) 818 d.addCallback(lambda items_comments_data: ('', items_comments_data))
815 d.addErrback(lambda failure: (unicode(failure.value), ([],{}))) 819 d.addErrback(lambda failure: (unicode(failure.value), ([],{})))
816 820
817 return self.rt_sessions.newSession(deferreds, client.profile) 821 return self.rt_sessions.newSession(deferreds, client.profile)
822
823 # atom feed
824
825 def _mbGetAtom(self, service_jid_s, node="", max_items=10, item_ids=None, extra_dict=None, profile_key=C.PROF_KEY_NONE):
826 """Get the atom feed of the last published microblogs
827
828 @param service_jid(jid.JID): jid of the publisher
829 @param node(unicode, None): node to get (or microblog node if None)
830 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
831 @param item_ids (list[unicode]): list of item IDs
832 @param rsm_request (rsm.RSMRequest): RSM request data
833 @param extra (dict): extra data
834 @param profile_key: %(doc_profile_key)s
835 @return: a deferred unicode (atom XML feed)
836 """
837 max_items = None if max_items == C.NO_LIMIT else max_items
838 extra = self._p.parseExtra(extra_dict)
839 return self.mbGetAtom(jid.JID(service_jid_s), node or None, max_items, item_ids, extra.rsm_request, extra.extra, profile_key)
840
841 @defer.inlineCallbacks
842 def mbGetAtom(self, service_jid, node=None, max_items=None, item_ids=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE):
843 """Get the atom feed of the last published microblogs
844
845 @param service_jid(jid.JID): jid of the publisher
846 @param node(unicode, None): node to get (or microblog node if None)
847 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
848 @param item_ids (list[unicode]): list of item IDs
849 @param rsm_request (rsm.RSMRequest): RSM request data
850 @param extra (dict): extra data
851 @param profile_key: %(doc_profile_key)s
852
853 @return: a deferred couple with the list of items and metadatas.
854 """
855 if node is None:
856 node = NS_MICROBLOG
857 items, metadata = yield self._p.getItems(service_jid, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=profile_key)
858
859 feed = """<?xml version="1.0" encoding="utf-8"?>
860 <feed xmlns="http://www.w3.org/2005/Atom">
861 <title>%(user)s's blogposts</title>
862 <link href="%(feed)s" rel="self" />
863 <link href="%(blog)s" />
864 <id>%(id)s</id>
865 <updated>%(date)s</updated>\n""" % {'user': service_jid.user,
866 'feed': 'http://%s/blog/%s/atom.xml' % (service_jid.host, service_jid.user),
867 'blog': 'http://%s/blog/%s' % (service_jid.host, service_jid.user),
868 'id': node,
869 'date': rfc3339.timestamp_from_tf(rfc3339.tf_utc())}
870
871 def removeAllURIs(element):
872 """Recursively remove the URIs of the element and its children.
873 Without that, the entry would still be valid but not displayed
874 by Firefox nor Thunderbird (and probably more readers)"""
875 element.uri = element.defaultUri = None
876 for child in element.children:
877 if isinstance(child, domish.Element):
878 removeAllURIs(child)
879
880 for item in items:
881 entry = item.firstChildElement()
882 removeAllURIs(entry)
883 feed += " " + entry.toXml() + "\n"
884 defer.returnValue(feed + "</feed>")
885