diff src/server/server.py @ 716:3b91225b457a

server + browser side: blogging refactoring (draft), huge commit sorry: /!\ everything is not working yet, group blog is not working for now - adaptation to backend changes - frontend commons part of blog have been moved to QuickFrontend - (editors) button "WYSIWYG edition" renamed to "preview" - (editors) Shift + [ENTER] is now used to send a text message, [ENTER] to finish a ligne normally - (editors) fixed modifiers handling - global simplification, resulting of the refactoring - with backend refactoring, we are now using PEP again, XEP-0277 compatibility is restored \o/
author Goffi <goffi@goffi.org>
date Sun, 16 Aug 2015 01:51:12 +0200
parents df8cb7bedfbf
children 5745b5e6586a
line wrap: on
line diff
--- a/src/server/server.py	Tue Jul 28 22:22:10 2015 +0200
+++ b/src/server/server.py	Sun Aug 16 01:51:12 2015 +0200
@@ -150,7 +150,8 @@
         self.sat_host = sat_host
 
     def asyncBridgeCall(self, method_name, *args, **kwargs):
-        """Call an asynchrone bridge method and return a deferred
+        """Call an asynchronous bridge method and return a deferred
+
         @param method_name: name of the method as a unicode
         @return: a deferred which trigger the result
 
@@ -258,108 +259,220 @@
         profile = ISATSession(self.session).profile
         return self.asyncBridgeCall("sendMessage", to_jid, msg, subject, type_, options, profile)
 
-    def jsonrpc_sendMblog(self, type_, dest, text, extra={}):
-        """ Send microblog message
-        @param type_ (unicode): one of "PUBLIC", "GROUP"
-        @param dest (tuple(unicode)): recipient groups (ignored for "PUBLIC")
-        @param text (unicode): microblog's text
-        """
-        profile = ISATSession(self.session).profile
-        extra['allow_comments'] = 'True'
-
-        if not type_:  # auto-detect
-            type_ = "PUBLIC" if dest == [] else "GROUP"
+    ## PubSub ##
 
-        if type_ in ("PUBLIC", "GROUP") and text:
-            if type_ == "PUBLIC":
-                #This text if for the public microblog
-                log.debug("sending public blog")
-                return self.sat_host.bridge.sendGroupBlog("PUBLIC", (), text, extra, profile)
-            else:
-                log.debug("sending group blog")
-                dest = dest if isinstance(dest, list) else [dest]
-                return self.sat_host.bridge.sendGroupBlog("GROUP", dest, text, extra, profile)
-        else:
-            raise Exception("Invalid data")
+    def jsonrpc_psDeleteNode(self, service, node):
+        """Delete a whole node
 
-    def jsonrpc_deleteMblog(self, pub_data, comments):
-        """Delete a microblog node
-        @param pub_data: a tuple (service, comment node identifier, item identifier)
-        @param comments: comments node identifier (for main item) or False
+        @param service (unicode): service jid
+        @param node (unicode): node to delete
         """
         profile = ISATSession(self.session).profile
-        return self.sat_host.bridge.deleteGroupBlog(pub_data, comments if comments else '', profile)
+        return self.asyncBridgeCall("psDeleteNode", service, node, profile)
+
+    # def jsonrpc_psRetractItem(self, service, node, item, notify):
+    #     """Delete a whole node
+
+    #     @param service (unicode): service jid
+    #     @param node (unicode): node to delete
+    #     @param items (iterable): id of item to retract
+    #     @param notify (bool): True if notification is required
+    #     """
+    #     profile = ISATSession(self.session).profile
+    #     return self.asyncBridgeCall("psRetractItem", service, node, item, notify, profile)
+
+    # def jsonrpc_psRetractItems(self, service, node, items, notify):
+    #     """Delete a whole node
 
-    def jsonrpc_updateMblog(self, pub_data, comments, message, extra={}):
-        """Modify a microblog node
-        @param pub_data: a tuple (service, comment node identifier, item identifier)
-        @param comments: comments node identifier (for main item) or False
-        @param message: new message
-        @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 = ISATSession(self.session).profile
-        if comments:
-            extra['allow_comments'] = 'True'
-        return self.sat_host.bridge.updateGroupBlog(pub_data, comments if comments else '', message, extra, profile)
+    #     @param service (unicode): service jid
+    #     @param node (unicode): node to delete
+    #     @param items (iterable): ids of items to retract
+    #     @param notify (bool): True if notification is required
+    #     """
+    #     profile = ISATSession(self.session).profile
+    #     return self.asyncBridgeCall("psRetractItems", service, node, items, notify, profile)
 
-    def jsonrpc_sendMblogComment(self, node, text, extra={}):
-        """ Send microblog message
-        @param node: url of the comments node
-        @param text: comment
+    ## microblogging ##
+
+    def jsonrpc_mbSend(self, service, node, mb_data):
+        """Send microblog data
+
+        @param service (unicode): service jid or empty string to use profile's microblog
+        @param node (unicode): publishing node, or empty string to use microblog node
+        @param mb_data(dict): microblog data
+        @return: a deferred
         """
         profile = ISATSession(self.session).profile
-        if node and text:
-            return self.sat_host.bridge.sendGroupBlogComment(node, text, extra, profile)
-        else:
-            raise Exception("Invalid data")
+        return self.asyncBridgeCall("mbSend", service, node, mb_data, profile)
+
+    def jsonrpc_mbRetract(self, service, node, items):
+        """Delete a whole node
 
-    def jsonrpc_getMblogs(self, publisher_jid, item_ids, max_items=C.RSM_MAX_ITEMS):
-        """Get specified microblogs posted by a contact
-        @param publisher_jid: jid of the publisher
-        @param item_ids: list of microblogs items IDs
-        @return list of microblog data (dict)"""
+        @param service (unicode): service jid, empty string for PEP
+        @param node (unicode): node to delete, empty string for default node
+        @param items (iterable): ids of items to retract
+        """
         profile = ISATSession(self.session).profile
-        d = self.asyncBridgeCall("getGroupBlogs", publisher_jid, item_ids, {'max_': unicode(max_items)}, False, profile)
-        return d
+        return self.asyncBridgeCall("mbRetract", service, node, items, profile)
+
+    def jsonrpc_mbGetLast(self, service_jid, node, max_items, extra):
+        """Get last microblogs from publisher_jid
 
-    def jsonrpc_getMblogsWithComments(self, publisher_jid, item_ids, max_comments=C.RSM_MAX_COMMENTS):
-        """Get specified microblogs posted by a contact and their comments
-        @param publisher_jid: jid of the publisher
-        @param item_ids: list of microblogs items IDs
-        @return list of couple (microblog data, list of microblog data)"""
+        @param service_jid (unicode): pubsub service, usually publisher jid
+        @param node(unicode): mblogs node, or empty string to get the defaut one
+        @param max_items (int): maximum number of item to get or C.NO_LIMIT to get everything
+        @param rsm (dict): TODO
+        @return: a deferred couple with the list of items and metadatas.
+        """
         profile = ISATSession(self.session).profile
-        d = self.asyncBridgeCall("getGroupBlogsWithComments", publisher_jid, item_ids, {}, max_comments, profile)
-        return d
+        return self.asyncBridgeCall("mbGetLast", service_jid, node, max_items, extra, profile)
 
-    def jsonrpc_getMassiveMblogs(self, publishers_type, publishers, rsm=None):
-        """Get lasts microblogs posted by several contacts at once
+    def jsonrpc_mbGetFromMany(self, publishers_type, publishers, max_items, extra):
+        """Get many blog nodes at once
 
         @param publishers_type (unicode): one of "ALL", "GROUP", "JID"
         @param publishers (tuple(unicode)): tuple of publishers (empty list for all, list of groups or list of jids)
-        @param rsm (dict): TODO
-        @return: dict{unicode: list[dict])
-            key: publisher's jid
-            value: list of microblog data (dict)
+        @param max_items (int): maximum number of item to get or C.NO_LIMIT to get everything
+        @param extra (dict): TODO
+        @return (str): RT Deferred session id
+        """
+        profile = ISATSession(self.session).profile
+        return self.sat_host.bridge.mbGetFromMany(publishers_type, publishers, max_items, extra, profile)
+
+    def jsonrpc_mbGetFromManyRTResult(self, rt_session):
+        """Get results from RealTime mbGetFromMany session
+
+        @param rt_session (str): RT Deferred session id
+        """
+        profile = ISATSession(self.session).profile
+        return self.asyncBridgeCall("mbGetFromManyRTResult", rt_session, profile)
+
+    def jsonrpc_mbGetFromManyWithComments(self, publishers_type, publishers, max_items, max_comments, rsm_dict, rsm_comments_dict):
+        """Helper method to get the microblogs and their comments in one shot
+
+        @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
+        @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
+        @param max_items (int): optional limit on the number of retrieved items.
+        @param max_comments (int): maximum number of comments to retrieve
+        @param rsm_dict (dict): RSM data for initial items only
+        @param rsm_comments_dict (dict): RSM data for comments only
+        @param profile_key: profile key
+        @return (str): RT Deferred session id
+        """
+        profile = ISATSession(self.session).profile
+        return self.sat_host.bridge.mbGetFromManyWithComments(publishers_type, publishers, max_items, max_comments, rsm_dict, rsm_comments_dict, profile)
+
+    def jsonrpc_mbGetFromManyWithCommentsRTResult(self, rt_session):
+        """Get results from RealTime mbGetFromManyWithComments session
+
+        @param rt_session (str): RT Deferred session id
         """
         profile = ISATSession(self.session).profile
-        if rsm is None:
-            rsm = {'max_': unicode(C.RSM_MAX_ITEMS)}
-        d = self.asyncBridgeCall("getMassiveGroupBlogs", publishers_type, publishers, rsm, profile)
-        self.sat_host.bridge.massiveSubscribeGroupBlogs(publishers_type, publishers, profile)
-        return d
+        return self.asyncBridgeCall("mbGetFromManyWithCommentsRTResult", rt_session, profile)
+
+
+    # def jsonrpc_sendMblog(self, type_, dest, text, extra={}):
+    #     """ Send microblog message
+    #     @param type_ (unicode): one of "PUBLIC", "GROUP"
+    #     @param dest (tuple(unicode)): recipient groups (ignored for "PUBLIC")
+    #     @param text (unicode): microblog's text
+    #     """
+    #     profile = ISATSession(self.session).profile
+    #     extra['allow_comments'] = 'True'
+
+    #     if not type_:  # auto-detect
+    #         type_ = "PUBLIC" if dest == [] else "GROUP"
+
+    #     if type_ in ("PUBLIC", "GROUP") and text:
+    #         if type_ == "PUBLIC":
+    #             #This text if for the public microblog
+    #             log.debug("sending public blog")
+    #             return self.sat_host.bridge.sendGroupBlog("PUBLIC", (), text, extra, profile)
+    #         else:
+    #             log.debug("sending group blog")
+    #             dest = dest if isinstance(dest, list) else [dest]
+    #             return self.sat_host.bridge.sendGroupBlog("GROUP", dest, text, extra, profile)
+    #     else:
+    #         raise Exception("Invalid data")
+
+    # def jsonrpc_deleteMblog(self, pub_data, comments):
+    #     """Delete a microblog node
+    #     @param pub_data: a tuple (service, comment node identifier, item identifier)
+    #     @param comments: comments node identifier (for main item) or False
+    #     """
+    #     profile = ISATSession(self.session).profile
+    #     return self.sat_host.bridge.deleteGroupBlog(pub_data, comments if comments else '', profile)
+
+    # def jsonrpc_updateMblog(self, pub_data, comments, message, extra={}):
+    #     """Modify a microblog node
+    #     @param pub_data: a tuple (service, comment node identifier, item identifier)
+    #     @param comments: comments node identifier (for main item) or False
+    #     @param message: new message
+    #     @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 = ISATSession(self.session).profile
+    #     if comments:
+    #         extra['allow_comments'] = 'True'
+    #     return self.sat_host.bridge.updateGroupBlog(pub_data, comments if comments else '', message, extra, profile)
 
-    def jsonrpc_getMblogComments(self, service, node, rsm=None):
-        """Get all comments of given node
-        @param service: jid of the service hosting the node
-        @param node: comments node
-        """
-        profile = ISATSession(self.session).profile
-        if rsm is None:
-            rsm = {'max_': unicode(C.RSM_MAX_COMMENTS)}
-        d = self.asyncBridgeCall("getGroupBlogComments", service, node, rsm, profile)
-        return d
+    # def jsonrpc_sendMblogComment(self, node, text, extra={}):
+    #     """ Send microblog message
+    #     @param node: url of the comments node
+    #     @param text: comment
+    #     """
+    #     profile = ISATSession(self.session).profile
+    #     if node and text:
+    #         return self.sat_host.bridge.sendGroupBlogComment(node, text, extra, profile)
+    #     else:
+    #         raise Exception("Invalid data")
+
+    # def jsonrpc_getMblogs(self, publisher_jid, item_ids, max_items=C.RSM_MAX_ITEMS):
+    #     """Get specified microblogs posted by a contact
+    #     @param publisher_jid: jid of the publisher
+    #     @param item_ids: list of microblogs items IDs
+    #     @return list of microblog data (dict)"""
+    #     profile = ISATSession(self.session).profile
+    #     d = self.asyncBridgeCall("getGroupBlogs", publisher_jid, item_ids, {'max_': unicode(max_items)}, False, profile)
+    #     return d
+
+    # def jsonrpc_getMblogsWithComments(self, publisher_jid, item_ids, max_comments=C.RSM_MAX_COMMENTS):
+    #     """Get specified microblogs posted by a contact and their comments
+    #     @param publisher_jid: jid of the publisher
+    #     @param item_ids: list of microblogs items IDs
+    #     @return list of couple (microblog data, list of microblog data)"""
+    #     profile = ISATSession(self.session).profile
+    #     d = self.asyncBridgeCall("getGroupBlogsWithComments", publisher_jid, item_ids, {}, max_comments, profile)
+    #     return d
+
+    # def jsonrpc_getMassiveMblogs(self, publishers_type, publishers, rsm=None):
+    #     """Get lasts microblogs posted by several contacts at once
+
+    #     @param publishers_type (unicode): one of "ALL", "GROUP", "JID"
+    #     @param publishers (tuple(unicode)): tuple of publishers (empty list for all, list of groups or list of jids)
+    #     @param rsm (dict): TODO
+    #     @return: dict{unicode: list[dict])
+    #         key: publisher's jid
+    #         value: list of microblog data (dict)
+    #     """
+    #     profile = ISATSession(self.session).profile
+    #     if rsm is None:
+    #         rsm = {'max_': unicode(C.RSM_MAX_ITEMS)}
+    #     d = self.asyncBridgeCall("getMassiveGroupBlogs", publishers_type, publishers, rsm, profile)
+    #     self.sat_host.bridge.massiveSubscribeGroupBlogs(publishers_type, publishers, profile)
+    #     return d
+
+    # def jsonrpc_getMblogComments(self, service, node, rsm=None):
+    #     """Get all comments of given node
+    #     @param service: jid of the service hosting the node
+    #     @param node: comments node
+    #     """
+    #     profile = ISATSession(self.session).profile
+    #     if rsm is None:
+    #         rsm = {'max_': unicode(C.RSM_MAX_COMMENTS)}
+    #     d = self.asyncBridgeCall("getGroupBlogComments", service, node, rsm, profile)
+    #     return d
 
     def jsonrpc_getPresenceStatuses(self):
         """Get Presence information for connected contacts"""
@@ -1099,7 +1212,7 @@
             for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated', 'askConfirmation', 'newAlert', 'paramUpdate']:
                 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
             #plugins
-            for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',
+            for signal_name in ['psEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',
                                 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore', 'tarotGamePlayers',
                                 'radiocolStarted', 'radiocolPreload', 'radiocolPlay', 'radiocolNoUpload', 'radiocolUploadOk', 'radiocolSongRejected', 'radiocolPlayers',
                                 'roomLeft', 'roomUserChangedNick', 'chatStateReceived']: