comparison sat/plugins/plugin_exp_events.py @ 3040:fee60f17ebac

jp: jp asyncio port: /!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\ This patch implements the port of jp to asyncio, so it is now correctly using the bridge asynchronously, and it can be used with bridges like `pb`. This also simplify the code, notably for things which were previously implemented with many callbacks (like pagination with RSM). During the process, some behaviours have been modified/fixed, in jp and backends, check diff for details.
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:56:41 +0200
parents ab2696e34d29
children 3c924cb207d9
comparison
equal deleted inserted replaced
3039:a1bc34f90fa5 3040:fee60f17ebac
379 379
380 yield self._p.publish(client, service, node, items=[item_elt]) 380 yield self._p.publish(client, service, node, items=[item_elt])
381 381
382 if register: 382 if register:
383 yield self.register( 383 yield self.register(
384 client, service, None, {}, node, event_id, event_elt, creator=True) 384 client, None, {}, service, node, event_id, item_elt, creator=True)
385 defer.returnValue(node) 385 defer.returnValue(node)
386 386
387 def _eventModify(self, service, node, id_, timestamp_update, data_update, 387 def _eventModify(self, service, node, id_, timestamp_update, data_update,
388 profile_key=C.PROF_KEY_NONE): 388 profile_key=C.PROF_KEY_NONE):
389 service = jid.JID(service) if service else None 389 service = jid.JID(service) if service else None
445 else: 445 else:
446 timestamp, data = self._parseEventElt(event_elt) 446 timestamp, data = self._parseEventElt(event_elt)
447 events.append((timestamp, data)) 447 events.append((timestamp, data))
448 defer.returnValue(events) 448 defer.returnValue(events)
449 449
450 def _eventInviteeGet(self, service, node, profile_key): 450 def _eventInviteeGet(self, service, node, invitee_jid_s, profile_key):
451 service = jid.JID(service) if service else None 451 service = jid.JID(service) if service else None
452 node = node if node else NS_EVENT 452 node = node if node else NS_EVENT
453 client = self.host.getClient(profile_key) 453 client = self.host.getClient(profile_key)
454 return self.eventInviteeGet(client, service, node) 454 invitee_jid = jid.JID(invitee_jid_s) if invitee_jid_s else None
455 455 return self.eventInviteeGet(client, service, node, invitee_jid)
456 @defer.inlineCallbacks 456
457 def eventInviteeGet(self, client, service, node): 457 @defer.inlineCallbacks
458 def eventInviteeGet(self, client, service, node, invitee_jid=None):
458 """Retrieve attendance from event node 459 """Retrieve attendance from event node
459 460
460 @param service(unicode, None): PubSub service 461 @param service(unicode, None): PubSub service
461 @param node(unicode): PubSub node of the event 462 @param node(unicode): PubSub node of the event's invitees
463 @param invitee_jid(jid.JId, None): jid of the invitee to retrieve (None to
464 retrieve profile's invitation). The bare jid correspond to the PubSub item id.
462 @return (dict): a dict with current attendance status, 465 @return (dict): a dict with current attendance status,
463 an empty dict is returned if nothing has been answered yed 466 an empty dict is returned if nothing has been answered yed
464 """ 467 """
468 if invitee_jid is None:
469 invitee_jid = client.jid
465 try: 470 try:
466 items, metadata = yield self._p.getItems( 471 items, metadata = yield self._p.getItems(
467 client, service, node, item_ids=[client.jid.userhost()] 472 client, service, node, item_ids=[invitee_jid.userhost()]
468 ) 473 )
469 event_elt = next(items[0].elements(NS_EVENT, "invitee")) 474 event_elt = next(items[0].elements(NS_EVENT, "invitee"))
470 except (exceptions.NotFound, IndexError): 475 except (exceptions.NotFound, IndexError):
471 # no item found, event data are not set yet 476 # no item found, event data are not set yet
472 defer.returnValue({}) 477 defer.returnValue({})