comparison sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3793:b5c9021020df

component AP gateway: convert `Delete` AP activities to corresponding Pubsub `retract`: when a `Delete` actity is received, the item is removed from cache, and the corresponding item `retract` is sent to local XMPP subscribers. rel 367
author Goffi <goffi@goffi.org>
date Fri, 17 Jun 2022 14:15:23 +0200
parents 865167c34b82
children d5f343939239
comparison
equal deleted inserted replaced
3792:865167c34b82 3793:b5c9021020df
1790 service, 1790 service,
1791 node, 1791 node,
1792 [(subscription.subscriber, None, [item_elt])] 1792 [(subscription.subscriber, None, [item_elt])]
1793 ) 1793 )
1794 1794
1795 async def newAPDeleteItem(
1796 self,
1797 client: SatXMPPEntity,
1798 destinee: Optional[jid.JID],
1799 node: str,
1800 item: dict,
1801 ) -> None:
1802 """Analyse, cache and send notification for received AP item
1803
1804 @param destinee: jid of the destinee,
1805 @param node: XMPP pubsub node
1806 @param item: AP object payload
1807 """
1808 item_id = item.get("id")
1809 if not item_id:
1810 raise exceptions.DataError('"id" attribute is missing in item')
1811 if self.isLocalURL(item_id):
1812 raise ValueError("Local IDs should not be used")
1813
1814 cached_node = await self.host.memory.storage.getPubsubNode(
1815 client, client.jid, node, with_subscriptions=True
1816 )
1817 if cached_node is None:
1818 log.warning(
1819 f"Received an item retract for node {node!r} at {client.jid} which is "
1820 "not cached"
1821 )
1822 else:
1823 await self.host.memory.storage.deletePubsubItems(cached_node, [item_id])
1824 # notifyRetract is expecting domish.Element instances
1825 item_elt = domish.Element((None, "item"))
1826 item_elt["id"] = item_id
1827 for subscription in cached_node.subscriptions:
1828 if subscription.state != SubscriptionState.SUBSCRIBED:
1829 continue
1830 self.pubsub_service.notifyRetract(
1831 client.jid,
1832 node,
1833 [(subscription.subscriber, None, [item_elt])]
1834 )