diff --git a/sat/plugins/plugin_xep_0470.py b/sat/plugins/plugin_xep_0470.py index e11f960f..dc9e3279 100644 --- a/sat/plugins/plugin_xep_0470.py +++ b/sat/plugins/plugin_xep_0470.py @@ -164,7 +164,9 @@ class PubsubAttachments: data: dict ) -> bool: """trigger to create attachment node on each publication""" - await self.create_attachments_node(client, service, node, item["id"]) + await self.create_attachments_node( + client, service, node, item["id"], autocreate=True + ) return True async def create_attachments_node( @@ -172,10 +174,27 @@ class PubsubAttachments: client: SatXMPPEntity, service: jid.JID, node: str, - item_id: str + item_id: str, + autocreate: bool = False ): - """Create node for attachements if necessary""" - node_config = await self._p.getConfiguration(client, service, node) + """Create node for attachements if necessary + + @param service: service of target node + @param node: node where target item is published + @param item_id: ID of target item + @param autocrate: if True, target node is create if it doesn't exist + """ + try: + node_config = await self._p.getConfiguration(client, service, node) + except error.StanzaError as e: + if e.condition == "item-not-found" and autocreate: + # we auto-create the missing node + await self._p.createNode( + client, service, node + ) + node_config = await self._p.getConfiguration(client, service, node) + else: + raise e try: # FIXME: check if this is the best publish_model option node_config.fields["pubsub#publish_model"].value = "open"