Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0060.py @ 3588:2c7a52a62be3
plugin XEP-0060: events callbacks can now be sync or async
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 29 Jul 2021 17:10:36 +0200 |
parents | 2715da5b2aa7 |
children | ed037c98df37 |
comparison
equal
deleted
inserted
replaced
3587:2715da5b2aa7 | 3588:2c7a52a62be3 |
---|---|
35 from sat.core.i18n import _ | 35 from sat.core.i18n import _ |
36 from sat.core.constants import Const as C | 36 from sat.core.constants import Const as C |
37 from sat.core.log import getLogger | 37 from sat.core.log import getLogger |
38 from sat.core.core_types import SatXMPPEntity | 38 from sat.core.core_types import SatXMPPEntity |
39 from sat.core import exceptions | 39 from sat.core import exceptions |
40 from sat.tools import utils | |
40 from sat.tools import sat_defer | 41 from sat.tools import sat_defer |
41 from sat.tools import xml_tools | 42 from sat.tools import xml_tools |
42 from sat.tools.common import data_format | 43 from sat.tools.common import data_format |
43 | 44 |
44 | 45 |
1505 | 1506 |
1506 | 1507 |
1507 def itemsReceived(self, event): | 1508 def itemsReceived(self, event): |
1508 log.debug("Pubsub items received") | 1509 log.debug("Pubsub items received") |
1509 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS): | 1510 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS): |
1510 callback(self.parent, event) | 1511 d = utils.asDeferred(callback, self.parent, event) |
1512 d.addErrback(lambda f: log.error( | |
1513 f"Error while running items event callback {callback}: {f}" | |
1514 )) | |
1511 client = self.parent | 1515 client = self.parent |
1512 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: | 1516 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: |
1513 raw_items = [i.toXml() for i in event.items] | 1517 raw_items = [i.toXml() for i in event.items] |
1514 self.host.bridge.psEventRaw( | 1518 self.host.bridge.psEventRaw( |
1515 event.sender.full(), | 1519 event.sender.full(), |
1520 ) | 1524 ) |
1521 | 1525 |
1522 def deleteReceived(self, event): | 1526 def deleteReceived(self, event): |
1523 log.debug(("Publish node deleted")) | 1527 log.debug(("Publish node deleted")) |
1524 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_DELETE): | 1528 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_DELETE): |
1525 callback(self.parent, event) | 1529 d = utils.asDeferred(callback, self.parent, event) |
1530 d.addErrback(lambda f: log.error( | |
1531 f"Error while running delete event callback {callback}: {f}" | |
1532 )) | |
1526 client = self.parent | 1533 client = self.parent |
1527 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: | 1534 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: |
1528 self.host.bridge.psEventRaw( | 1535 self.host.bridge.psEventRaw( |
1529 event.sender.full(), event.nodeIdentifier, C.PS_DELETE, [], client.profile | 1536 event.sender.full(), event.nodeIdentifier, C.PS_DELETE, [], client.profile |
1530 ) | 1537 ) |