diff src/plugins/plugin_xep_0163.py @ 1459:4c4f88d7b156

plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry): /!\ not everything is working yet, and specially groupblogs are broken /!\ - renamed bridge api to use prefixed methods (e.g. psSubscribeToMany instead of subscribeToMany in PubSub) - (xep-0060): try to find a default PubSub service, and put it in client.pubsub_service - (xep-0060): extra dictionary can be used in bridge method for RSM and other options - (xep-0060): XEP_0060.addManagedNode and XEP_0060.removeManagedNode allow to easily catch notifications for a specific node - (xep-0060): retractItem manage "notify" attribute - (xep-0060): new signal psEvent will be used to transmit notifications to frontends - (xep-0060, constants): added a bunch of useful constants - (xep-0163): removed personalEvent in favor of psEvent - (xep-0163): addPEPEvent now filter non PEP events for in_callback - (xep-0277): use of new XEP-0060 plugin's addManagedNode - (xep-0277): fixed author handling for incoming blogs: author is the human readable name, author_jid it jid, and author_jid_verified is set to True is the jid is checked - (xep-0277): reworked data2entry with Twisted instead of feed, item_id can now be specified, <content/> is changed to <title/> if there is only content - (xep-0277): comments are now managed here (core removed from groupblog) - (xep-0277): (comments) node is created if needed, default pubsub service is used if available, else PEP - (xep-0277): retract is managed
author Goffi <goffi@goffi.org>
date Sun, 16 Aug 2015 00:39:44 +0200
parents 3265a2639182
children d17772b0fe22
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0163.py	Sun Aug 16 00:06:59 2015 +0200
+++ b/src/plugins/plugin_xep_0163.py	Sun Aug 16 00:39:44 2015 +0200
@@ -49,43 +49,62 @@
         self.pep_events = set()
         self.pep_out_cb = {}
         host.trigger.add("PubSub Disco Info", self.disoInfoTrigger)
-        host.bridge.addSignal("personalEvent", ".plugin", signature='ssa{ss}s')  # args: from (jid), type(MOOD, TUNE, etc), data, profile
-        host.bridge.addMethod("sendPersonalEvent", ".plugin", in_sign='sa{ss}s', out_sign='', method=self.sendPersonalEvent, async=True)  # args: type(MOOD, TUNE, etc), data, profile_key;
+        host.bridge.addMethod("PEPSend", ".plugin", in_sign='sa{ss}s', out_sign='', method=self.PEPSend, async=True)  # args: type(MOOD, TUNE, etc), data, profile_key;
         self.addPEPEvent("MOOD", NS_USER_MOOD, self.userMoodCB, self.sendMood)
 
     def disoInfoTrigger(self, disco_info, profile):
         """Add info from managed PEP
+
         @param disco_info: list of disco feature as returned by PubSub,
             will be filled with PEP features
-        @param profile: profile we are handling"""
+        @param profile: profile we are handling
+        """
         disco_info.extend(map(disco.DiscoFeature, self.pep_events))
         return True
 
-    def addPEPEvent(self, event_type, name, in_callback, out_callback=None, notify=True):
+    def addPEPEvent(self, event_type, node, in_callback, out_callback=None, notify=True):
         """Add a Personal Eventing Protocol event manager
-        @param event_type: type of the event (always uppercase), can be MOOD, TUNE, etc
-        @param name: namespace of the node (e.g. http://jabber.org/protocol/mood for User Mood)
-        @param in_callback: method to call when this event occur
-        @param out_callback: method to call when we want to publish this event (must return a deferred)
-        @param notify: add autosubscribe (+notify) if True"""
+
+        @param event_type(unicode): type of the event (always uppercase), can be MOOD, TUNE, etc
+        @param node(unicode): namespace of the node (e.g. http://jabber.org/protocol/mood for User Mood)
+        @param in_callback(callable): method to call when this event occur
+            the callable will be called with (itemsEvent, profile) as arguments
+        @param out_callback(callable,None): method to call when we want to publish this event (must return a deferred)
+            the callable will be called when sendPEPEvent is called
+        @param notify(bool): add autosubscribe (+notify) if True
+        """
         if out_callback:
             self.pep_out_cb[event_type] = out_callback
-        self.pep_events.add(name)
+        self.pep_events.add(node)
         if notify:
-            self.pep_events.add(name + "+notify")
-        self.host.plugins["XEP-0060"].addManagedNode(name, in_callback)
+            self.pep_events.add(node + "+notify")
+        def filterPEPEvent(itemsEvent, profile):
+            """Ignore messages which are not coming from PEP (i.e. main server)
 
-    def sendPEPEvent(self, namespace, data, profile):
+            @param itemsEvent(pubsub.ItemsEvent): pubsub event
+            @param profile(unicode): %(doc_profile)s
+            """
+            if itemsEvent.sender.user or itemsEvent.sender.resource:
+                log.debug("ignoring non PEP event from {} (profile={})".format(itemsEvent.sender.full(), profile))
+                return
+            in_callback(itemsEvent, profile)
+
+        self.host.plugins["XEP-0060"].addManagedNode(node, items_cb=filterPEPEvent)
+
+    def sendPEPEvent(self, node, data, profile):
         """Publish the event data
-        @param namespace: node namespace
+
+        @param node(unicode): node namespace
         @param data: domish.Element to use as payload
-        @param profile: profile which send the data"""
+        @param profile: profile which send the data
+        """
 
         item = pubsub.Item(payload=data)
-        return self.host.plugins["XEP-0060"].publish(None, namespace, [item], profile_key=profile)
+        return self.host.plugins["XEP-0060"].publish(None, node, [item], profile_key=profile)
 
-    def sendPersonalEvent(self, event_type, data, profile_key=C.PROF_KEY_NONE):
+    def PEPSend(self, event_type, data, profile_key=C.PROF_KEY_NONE):
         """Send personal event after checking the data is alright
+
         @param event_type: type of event (eg: MOOD, TUNE), must be in self.pep_out_cb.keys()
         @param data: dict of {string:string} of event_type dependant data
         @param profile_key: profile who send the event
@@ -112,10 +131,12 @@
         if not mood:
             log.debug(_("No mood found"))
             return
-        self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": mood.value or "", "text": mood.text or ""}, profile)
+        self.host.bridge.psEvent(C.PS_PEP, itemsEvent.sender.full(), itemsEvent.nodeIdentifier,
+                                 "MOOD", {"mood": mood.value or "", "text": mood.text or ""}, profile)
 
     def sendMood(self, data, profile):
         """Send XEP-0107's User Mood
+
         @param data: must include mood and text
         @param profile: profile which send the mood"""
         try: