# HG changeset patch # User Goffi # Date 1663792590 -7200 # Node ID 43024e50b701aed902f858e7eac31d08e4de7bce # Parent 6c93a18b6250616701dd5c45310fedb8a5d8faa6 plugin XEP-0470: add `create_attachments_node` method: this method create the attachments node if it doesn't already exists, and use same access model as target item, and an `open` publish model. rel 372 diff -r 6c93a18b6250 -r 43024e50b701 sat/plugins/plugin_xep_0470.py --- a/sat/plugins/plugin_xep_0470.py Wed Sep 21 22:33:59 2022 +0200 +++ b/sat/plugins/plugin_xep_0470.py Wed Sep 21 22:36:30 2022 +0200 @@ -164,16 +164,31 @@ data: dict ) -> bool: """trigger to create attachment node on each publication""" + await self.create_attachments_node(client, service, node, item["id"]) + return True + + async def create_attachments_node( + self, + client: SatXMPPEntity, + service: jid.JID, + node: str, + item_id: str + ): + """Create node for attachements if necessary""" node_config = await self._p.getConfiguration(client, service, node) - attachment_node = self.getAttachmentNodeName(service, node, item["id"]) + try: + # FIXME: check if this is the best publish_model option + node_config.fields["pubsub#publish_model"].value = "open" + except KeyError: + log.warning("pubsub#publish_model field is missing") + attachment_node = self.getAttachmentNodeName(service, node, item_id) # we use the same options as target node try: await self._p.createIfNewNode( client, service, attachment_node, options=dict(node_config) ) except Exception as e: - log.warning(f"Can't create attachment node {attachment_node}: {e}]") - return True + log.warning(f"Can't create attachment node {attachment_node}: {e}") def items2attachmentData( self,