plugin XEP-0470: fix autocreate in create_attachments_node:

Due to config check, `create_attachments_node` was failing when the target node was not
already existing. However, this is the case when an item is published and `autocreate` is
expected, thus the node is now created if not already existing and new `autocreate`
argument is set.
This commit is contained in:
Goffi 2022-10-15 20:38:33 +02:00
commit 9f047d311c

View file

@ -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"