comparison src/plugins/plugin_xep_0060.py @ 2185:dd53d7a3219a

plugin XEP-0060: added psGet bridge method
author Goffi <goffi@goffi.org>
date Sun, 12 Mar 2017 23:28:04 +0100
parents a543eda2c923
children d65275ac39b3
comparison
equal deleted inserted replaced
2184:e0f91efa404a 2185:dd53d7a3219a
83 log.info(_(u"PubSub plugin initialization")) 83 log.info(_(u"PubSub plugin initialization"))
84 self.host = host 84 self.host = host
85 self._mam = host.plugins.get('XEP-0313') 85 self._mam = host.plugins.get('XEP-0313')
86 self._node_cb = {} # dictionnary of callbacks for node (key: node, value: list of callbacks) 86 self._node_cb = {} # dictionnary of callbacks for node (key: node, value: list of callbacks)
87 self.rt_sessions = sat_defer.RTDeferredSessions() 87 self.rt_sessions = sat_defer.RTDeferredSessions()
88 host.bridge.addMethod("psGet", ".plugin", in_sign='ssiassa{ss}s', out_sign='(asa{ss})', method=self._getItems, async=True)
88 host.bridge.addMethod("psDeleteNode", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True) 89 host.bridge.addMethod("psDeleteNode", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True)
89 host.bridge.addMethod("psRetractItem", ".plugin", in_sign='sssbs', out_sign='', method=self._retractItem, async=True) 90 host.bridge.addMethod("psRetractItem", ".plugin", in_sign='sssbs', out_sign='', method=self._retractItem, async=True)
90 host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True) 91 host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True)
91 host.bridge.addMethod("psSubscribeToMany", ".plugin", in_sign='a(ss)sa{ss}s', out_sign='s', method=self._subscribeToMany) 92 host.bridge.addMethod("psSubscribeToMany", ".plugin", in_sign='a(ss)sa{ss}s', out_sign='s', method=self._subscribeToMany)
92 host.bridge.addMethod("psGetSubscribeRTResult", ".plugin", in_sign='ss', out_sign='(ua(sss))', method=self._manySubscribeRTResult, async=True) 93 host.bridge.addMethod("psGetSubscribeRTResult", ".plugin", in_sign='ss', out_sign='(ua(sss))', method=self._manySubscribeRTResult, async=True)
263 .elements('http://jabber.org/protocol/pubsub#event', 'items').next() 264 .elements('http://jabber.org/protocol/pubsub#event', 'items').next()
264 .elements('http://jabber.org/protocol/pubsub#event', 'item').next()) 265 .elements('http://jabber.org/protocol/pubsub#event', 'item').next())
265 except StopIteration: 266 except StopIteration:
266 raise exceptions.DataError(u"Can't find Item in MAM message element") 267 raise exceptions.DataError(u"Can't find Item in MAM message element")
267 return item_elt 268 return item_elt
269
270 def _getItems(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra_dict=None, profile_key=C.PROF_KEY_NONE):
271 """Get items from pubsub node
272
273 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
274 """
275 service = jid.JID(service) if service else None
276 max_items = None if max_items == C.NO_LIMIT else max_items
277 extra = self.parseExtra(extra_dict)
278 d = self.getItems(service, node or None, max_items or None, item_ids, sub_id or None, extra.rsm_request, extra.extra, profile_key)
279 d.addCallback(self.serItemsData)
280 return d
268 281
269 def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): 282 def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE):
270 """Retrieve pubsub items from a node. 283 """Retrieve pubsub items from a node.
271 284
272 @param service (JID, None): pubsub service. 285 @param service (JID, None): pubsub service.