comparison 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
comparison
equal deleted inserted replaced
1458:832846fefe85 1459:4c4f88d7b156
47 log.info(_("PEP plugin initialization")) 47 log.info(_("PEP plugin initialization"))
48 self.host = host 48 self.host = host
49 self.pep_events = set() 49 self.pep_events = set()
50 self.pep_out_cb = {} 50 self.pep_out_cb = {}
51 host.trigger.add("PubSub Disco Info", self.disoInfoTrigger) 51 host.trigger.add("PubSub Disco Info", self.disoInfoTrigger)
52 host.bridge.addSignal("personalEvent", ".plugin", signature='ssa{ss}s') # args: from (jid), type(MOOD, TUNE, etc), data, profile 52 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;
53 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;
54 self.addPEPEvent("MOOD", NS_USER_MOOD, self.userMoodCB, self.sendMood) 53 self.addPEPEvent("MOOD", NS_USER_MOOD, self.userMoodCB, self.sendMood)
55 54
56 def disoInfoTrigger(self, disco_info, profile): 55 def disoInfoTrigger(self, disco_info, profile):
57 """Add info from managed PEP 56 """Add info from managed PEP
57
58 @param disco_info: list of disco feature as returned by PubSub, 58 @param disco_info: list of disco feature as returned by PubSub,
59 will be filled with PEP features 59 will be filled with PEP features
60 @param profile: profile we are handling""" 60 @param profile: profile we are handling
61 """
61 disco_info.extend(map(disco.DiscoFeature, self.pep_events)) 62 disco_info.extend(map(disco.DiscoFeature, self.pep_events))
62 return True 63 return True
63 64
64 def addPEPEvent(self, event_type, name, in_callback, out_callback=None, notify=True): 65 def addPEPEvent(self, event_type, node, in_callback, out_callback=None, notify=True):
65 """Add a Personal Eventing Protocol event manager 66 """Add a Personal Eventing Protocol event manager
66 @param event_type: type of the event (always uppercase), can be MOOD, TUNE, etc 67
67 @param name: namespace of the node (e.g. http://jabber.org/protocol/mood for User Mood) 68 @param event_type(unicode): type of the event (always uppercase), can be MOOD, TUNE, etc
68 @param in_callback: method to call when this event occur 69 @param node(unicode): namespace of the node (e.g. http://jabber.org/protocol/mood for User Mood)
69 @param out_callback: method to call when we want to publish this event (must return a deferred) 70 @param in_callback(callable): method to call when this event occur
70 @param notify: add autosubscribe (+notify) if True""" 71 the callable will be called with (itemsEvent, profile) as arguments
72 @param out_callback(callable,None): method to call when we want to publish this event (must return a deferred)
73 the callable will be called when sendPEPEvent is called
74 @param notify(bool): add autosubscribe (+notify) if True
75 """
71 if out_callback: 76 if out_callback:
72 self.pep_out_cb[event_type] = out_callback 77 self.pep_out_cb[event_type] = out_callback
73 self.pep_events.add(name) 78 self.pep_events.add(node)
74 if notify: 79 if notify:
75 self.pep_events.add(name + "+notify") 80 self.pep_events.add(node + "+notify")
76 self.host.plugins["XEP-0060"].addManagedNode(name, in_callback) 81 def filterPEPEvent(itemsEvent, profile):
82 """Ignore messages which are not coming from PEP (i.e. main server)
77 83
78 def sendPEPEvent(self, namespace, data, profile): 84 @param itemsEvent(pubsub.ItemsEvent): pubsub event
85 @param profile(unicode): %(doc_profile)s
86 """
87 if itemsEvent.sender.user or itemsEvent.sender.resource:
88 log.debug("ignoring non PEP event from {} (profile={})".format(itemsEvent.sender.full(), profile))
89 return
90 in_callback(itemsEvent, profile)
91
92 self.host.plugins["XEP-0060"].addManagedNode(node, items_cb=filterPEPEvent)
93
94 def sendPEPEvent(self, node, data, profile):
79 """Publish the event data 95 """Publish the event data
80 @param namespace: node namespace 96
97 @param node(unicode): node namespace
81 @param data: domish.Element to use as payload 98 @param data: domish.Element to use as payload
82 @param profile: profile which send the data""" 99 @param profile: profile which send the data
100 """
83 101
84 item = pubsub.Item(payload=data) 102 item = pubsub.Item(payload=data)
85 return self.host.plugins["XEP-0060"].publish(None, namespace, [item], profile_key=profile) 103 return self.host.plugins["XEP-0060"].publish(None, node, [item], profile_key=profile)
86 104
87 def sendPersonalEvent(self, event_type, data, profile_key=C.PROF_KEY_NONE): 105 def PEPSend(self, event_type, data, profile_key=C.PROF_KEY_NONE):
88 """Send personal event after checking the data is alright 106 """Send personal event after checking the data is alright
107
89 @param event_type: type of event (eg: MOOD, TUNE), must be in self.pep_out_cb.keys() 108 @param event_type: type of event (eg: MOOD, TUNE), must be in self.pep_out_cb.keys()
90 @param data: dict of {string:string} of event_type dependant data 109 @param data: dict of {string:string} of event_type dependant data
91 @param profile_key: profile who send the event 110 @param profile_key: profile who send the event
92 """ 111 """
93 profile = self.host.memory.getProfileName(profile_key) 112 profile = self.host.memory.getProfileName(profile_key)
110 return 129 return
111 mood = Mood.fromXml(mood_elt) 130 mood = Mood.fromXml(mood_elt)
112 if not mood: 131 if not mood:
113 log.debug(_("No mood found")) 132 log.debug(_("No mood found"))
114 return 133 return
115 self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": mood.value or "", "text": mood.text or ""}, profile) 134 self.host.bridge.psEvent(C.PS_PEP, itemsEvent.sender.full(), itemsEvent.nodeIdentifier,
135 "MOOD", {"mood": mood.value or "", "text": mood.text or ""}, profile)
116 136
117 def sendMood(self, data, profile): 137 def sendMood(self, data, profile):
118 """Send XEP-0107's User Mood 138 """Send XEP-0107's User Mood
139
119 @param data: must include mood and text 140 @param data: must include mood and text
120 @param profile: profile which send the mood""" 141 @param profile: profile which send the mood"""
121 try: 142 try:
122 value = data['mood'].lower() 143 value = data['mood'].lower()
123 text = data['text'] if 'text' in data else '' 144 text = data['text'] if 'text' in data else ''