diff src/plugins/plugin_xep_0277.py @ 1664:5d0ff155be1a

plugin XEP-0277: tags are handled through atom categories
author Goffi <goffi@goffi.org>
date Tue, 24 Nov 2015 23:18:32 +0100
parents 96ee986dab3c
children 1895846fc9cb
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Tue Nov 24 16:21:18 2015 +0100
+++ b/src/plugins/plugin_xep_0277.py	Tue Nov 24 23:18:32 2015 +0100
@@ -28,6 +28,7 @@
 from sat.core import exceptions
 from sat.tools import xml_tools
 from sat.tools import sat_defer
+from sat.tools import common
 
 # XXX: tmp.pubsub is actually use instead of wokkel version
 from wokkel import pubsub
@@ -314,6 +315,10 @@
             else:
                 microblog_data['author_email'] = unicode(email_elt)
 
+            # categories
+            categories = (category_elt.getAttribute('term','') for category_elt in entry_elt.elements(NS_ATOM, 'category'))
+            common.iter2dict('tag', categories, microblog_data)
+
         defer.returnValue(microblog_data)
 
     @defer.inlineCallbacks
@@ -399,6 +404,11 @@
         entry_elt.addElement('published',
             content=rfc3339.timestamp_from_tf(float(data.get('published', current_time))))
 
+        ## categories ##
+        for tag in common.dict2iter("tag", data):
+            category_elt = entry_elt.addElement("category")
+            category_elt['term'] = tag
+
         ## id ##
         entry_id = data.get('id', item_id) # FIXME: use a proper id (see XEP-0277 ยง7.1)
         entry_elt.addElement('id', content=entry_id) #