changeset 708:6aa71c853bf5

plugin group blog: management of extra data/rich text for blog comments
author Goffi <goffi@goffi.org>
date Fri, 15 Nov 2013 15:27:03 +0100
parents 890fbf2d7fdd
children 648511e42a69
files src/plugins/plugin_misc_groupblog.py
diffstat 1 files changed, 27 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py	Thu Nov 14 18:36:02 2013 +0100
+++ b/src/plugins/plugin_misc_groupblog.py	Fri Nov 15 15:27:03 2013 +0100
@@ -20,9 +20,8 @@
 from logging import debug, info, warning, error
 from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
-
+from sat.core import exceptions
 from wokkel import disco, data_form, iwokkel
-
 from zope.interface import implements
 
 import uuid
@@ -88,7 +87,7 @@
                               method=self.sendGroupBlog,
                               async=True)
 
-        host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='sss', out_sign='',
+        host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='ssa{ss}s', out_sign='',
                               method=self.sendGroupBlogComment,
                               async=True)
 
@@ -121,14 +120,13 @@
         return GroupBlog_handler()
 
     @defer.inlineCallbacks
-    def initialise(self, profile_key):
+    def _initialise(self, profile_key):
         """Check that this data for this profile are initialised, and do it else
         @param client: client of the profile
         @profile_key: %(doc_profile)s"""
         profile = self.host.memory.getProfileName(profile_key)
         if not profile:
-            error(_("Unknown profile"))
-            raise Exception("Unknown profile")
+            raise exceptions.ProfileUnknownError
 
         client = self.host.getClient(profile)
         if not client:
@@ -328,7 +326,7 @@
         @param extra: dict which option name as key, which can be:
             - allow_comments: True to accept comments, False else (default: False)
             - rich: if present, contain rich text in currently selected syntax
-        @profile_key: %(doc_profile)s
+        @profile_key: %(doc_profile_key)s
         """
 
         def initialised(result):
@@ -348,25 +346,31 @@
                 error(_("Unknown access type"))
                 raise BadAccessTypeError
 
-        return self.initialise(profile_key).addCallback(initialised)
+        return self._initialise(profile_key).addCallback(initialised)
 
-    def sendGroupBlogComment(self, node_url, message, profile_key='@NONE@'):
+    def sendGroupBlogComment(self, node_url, message, extra, profile_key='@NONE@'):
         """Publish a comment in the given node
         @param node url: link to the comments node as specified in XEP-0277 and given in microblog data's comments key
         @param message: comment
+        @param extra: dict which option name as key, which can be:
+            - allow_comments: True to accept an other level of comments, False else (default: False)
+            - rich: if present, contain rich text in currently selected syntax
         @profile_key: %(doc_profile)s
         """
-        profile = self.host.memory.getProfileName(profile_key)
-        if not profile:
-            error(_("Unknown profile"))
-            raise Exception("Unknown profile")
+        def initialised(result):
+            profile, client = result
+            service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url)
+            mblog_data = {'content': message}
+            if 'rich' in extra:
+                mblog_data['rich'] = extra['rich']
+            if 'allow_comments' in extra:
+                raise NotImplementedError # TODO
+            entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)
+            entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile))
+            return entry_d
 
-        service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url)
+        return self._initialise(profile_key).addCallback(initialised)
 
-        mblog_data = {'content': message}
-        entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)
-        entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile))
-        return entry_d
 
     @defer.inlineCallbacks
     def _itemsConstruction(self, items, pub_jid, client):
@@ -409,7 +413,7 @@
             return d
 
         #TODO: we need to use the server corresponding the the host of the jid
-        return self.initialise(profile_key).addCallback(initialised)
+        return self._initialise(profile_key).addCallback(initialised)
 
     def getGroupBlogComments(self, service_s, node, profile_key='@NONE@'):
         """Get all comments of given node
@@ -429,7 +433,7 @@
             return d
 
         #TODO: we need to use the server corresponding the the host of the jid
-        return self.initialise(profile_key).addCallback(initialised)
+        return self._initialise(profile_key).addCallback(initialised)
 
     def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'):
         """Get the last published microblogs for a list of groups or jids
@@ -487,7 +491,7 @@
             raise Exception("Bad call, unknown publishers_type")
         if publishers_type == "ALL" and publishers:
             raise Exception("Publishers list must be empty when getting microblogs for all contacts")
-        return self.initialise(profile_key).addCallback(initialised)
+        return self._initialise(profile_key).addCallback(initialised)
         #TODO: we need to use the server corresponding the the host of the jid
 
     def subscribeGroupBlog(self, pub_jid, profile_key='@NONE@'):
@@ -498,7 +502,7 @@
             return d
 
         #TODO: we need to use the server corresponding the the host of the jid
-        return self.initialise(profile_key).addCallback(initialised)
+        return self._initialise(profile_key).addCallback(initialised)
 
     def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'):
         """Subscribe microblogs for a list of groups or jids
@@ -535,7 +539,7 @@
             raise Exception("Bad call, unknown publishers_type")
         if publishers_type == "ALL" and publishers:
             raise Exception("Publishers list must be empty when getting microblogs for all contacts")
-        return self.initialise(profile_key).addCallback(initialised)
+        return self._initialise(profile_key).addCallback(initialised)
         #TODO: we need to use the server corresponding the the host of the jid