comparison sat/plugins/plugin_xep_0470.py @ 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 aa7197b67c26
children 2b2856ae5eeb
comparison
equal deleted inserted replaced
3900:6c93a18b6250 3901:43024e50b701
162 node: str, 162 node: str,
163 item: domish.Element, 163 item: domish.Element,
164 data: dict 164 data: dict
165 ) -> bool: 165 ) -> bool:
166 """trigger to create attachment node on each publication""" 166 """trigger to create attachment node on each publication"""
167 await self.create_attachments_node(client, service, node, item["id"])
168 return True
169
170 async def create_attachments_node(
171 self,
172 client: SatXMPPEntity,
173 service: jid.JID,
174 node: str,
175 item_id: str
176 ):
177 """Create node for attachements if necessary"""
167 node_config = await self._p.getConfiguration(client, service, node) 178 node_config = await self._p.getConfiguration(client, service, node)
168 attachment_node = self.getAttachmentNodeName(service, node, item["id"]) 179 try:
180 # FIXME: check if this is the best publish_model option
181 node_config.fields["pubsub#publish_model"].value = "open"
182 except KeyError:
183 log.warning("pubsub#publish_model field is missing")
184 attachment_node = self.getAttachmentNodeName(service, node, item_id)
169 # we use the same options as target node 185 # we use the same options as target node
170 try: 186 try:
171 await self._p.createIfNewNode( 187 await self._p.createIfNewNode(
172 client, service, attachment_node, options=dict(node_config) 188 client, service, attachment_node, options=dict(node_config)
173 ) 189 )
174 except Exception as e: 190 except Exception as e:
175 log.warning(f"Can't create attachment node {attachment_node}: {e}]") 191 log.warning(f"Can't create attachment node {attachment_node}: {e}")
176 return True
177 192
178 def items2attachmentData( 193 def items2attachmentData(
179 self, 194 self,
180 client: SatXMPPEntity, 195 client: SatXMPPEntity,
181 items: List[domish.Element] 196 items: List[domish.Element]