changeset 1671:1895846fc9cb

plugin XEP-0277, group blog: added item2data trigger + group permission are parsed when receiving a new item
author Goffi <goffi@goffi.org>
date Wed, 25 Nov 2015 10:45:22 +0100
parents 3690b4d4157e
children dbd7c79aab2b
files src/plugins/plugin_misc_groupblog.py src/plugins/plugin_xep_0277.py
diffstat 2 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py	Wed Nov 25 02:06:44 2015 +0100
+++ b/src/plugins/plugin_misc_groupblog.py	Wed Nov 25 10:45:22 2015 +0100
@@ -131,6 +131,7 @@
         #                       async=True)
 
         # host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
+        host.trigger.add("XEP-0277_item2data", self._item2dataTrigger)
         host.trigger.add("XEP-0277_data2entry", self._data2entryTrigger)
         host.trigger.add("XEP-0277_comments", self._commentsTrigger)
 
@@ -165,6 +166,15 @@
                 log.error("Service should be available !")
             return {}
 
+    def _item2dataTrigger(self, item_elt, entry_elt, microblog_data):
+        """Parse item to find group permission elements"""
+        config_form = data_form.findForm(item_elt, NS_PUBSUB_ITEM_CONFIG)
+        if config_form is None:
+            return
+        access_model = config_form.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN)
+        if access_model == self._p.ACCESS_ROSTER:
+            common.iter2dict('group', config_form.fields[self._p.OPT_ROSTER_GROUPS_ALLOWED].values, microblog_data)
+
     def _data2entryTrigger(self, client, mb_data, entry_elt, item_elt):
         """Build fine access permission if needed
 
--- a/src/plugins/plugin_xep_0277.py	Wed Nov 25 02:06:44 2015 +0100
+++ b/src/plugins/plugin_xep_0277.py	Wed Nov 25 10:45:22 2015 +0100
@@ -319,6 +319,10 @@
             categories = (category_elt.getAttribute('term','') for category_elt in entry_elt.elements(NS_ATOM, 'category'))
             common.iter2dict('tag', categories, microblog_data)
 
+        ## the trigger ##
+        # if other plugins have things to add or change
+        yield self.host.trigger.point("XEP-0277_item2data", item_elt, entry_elt, microblog_data)
+
         defer.returnValue(microblog_data)
 
     @defer.inlineCallbacks