Mercurial > libervia-backend
changeset 3901:43024e50b701
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
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 21 Sep 2022 22:36:30 +0200 |
parents | 6c93a18b6250 |
children | 32b38dd3ac18 |
files | sat/plugins/plugin_xep_0470.py |
diffstat | 1 files changed, 18 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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,