Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_forums.py @ 3515:2dce411c2647
plugin misc forums: use rich content in createTopic
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 May 2021 18:23:42 +0200 |
parents | be6d91572633 |
children | 3fd60beb9b92 |
comparison
equal
deleted
inserted
replaced
3514:6d9c9e2dca0a | 3515:2dce411c2647 |
---|---|
270 topics.append(topic) | 270 topics.append(topic) |
271 defer.returnValue((topics, metadata)) | 271 defer.returnValue((topics, metadata)) |
272 | 272 |
273 def _createTopic(self, service, node, mb_data, profile_key): | 273 def _createTopic(self, service, node, mb_data, profile_key): |
274 client = self.host.getClient(profile_key) | 274 client = self.host.getClient(profile_key) |
275 return self.createTopic(client, jid.JID(service), node, mb_data) | 275 return defer.ensureDeferred( |
276 | 276 self.createTopic(client, jid.JID(service), node, mb_data) |
277 @defer.inlineCallbacks | 277 ) |
278 def createTopic(self, client, service, node, mb_data): | 278 |
279 async def createTopic(self, client, service, node, mb_data): | |
279 try: | 280 try: |
280 title = mb_data['title'] | 281 title = mb_data['title'] |
281 if not 'content' in mb_data: | 282 content = mb_data.pop('content') |
282 raise KeyError('content') | |
283 except KeyError as e: | 283 except KeyError as e: |
284 raise exceptions.DataError("missing mandatory data: {key}".format(key=e.args[0])) | 284 raise exceptions.DataError("missing mandatory data: {key}".format(key=e.args[0])) |
285 | 285 else: |
286 mb_data["content_rich"] = content | |
286 topic_node = FORUM_TOPIC_NODE_TPL.format(node=node, uuid=shortuuid.uuid()) | 287 topic_node = FORUM_TOPIC_NODE_TPL.format(node=node, uuid=shortuuid.uuid()) |
287 yield self._p.createNode(client, service, topic_node, self._node_options) | 288 await self._p.createNode(client, service, topic_node, self._node_options) |
288 self._m.send(client, mb_data, service, topic_node) | 289 await self._m.send(client, mb_data, service, topic_node) |
289 topic_uri = uri.buildXMPPUri('pubsub', | 290 topic_uri = uri.buildXMPPUri('pubsub', |
290 subtype='microblog', | 291 subtype='microblog', |
291 path=service.full(), | 292 path=service.full(), |
292 node=topic_node) | 293 node=topic_node) |
293 topic_elt = domish.Element((NS_FORUMS, 'topic')) | 294 topic_elt = domish.Element((NS_FORUMS, 'topic')) |
294 topic_elt['uri'] = topic_uri | 295 topic_elt['uri'] = topic_uri |
295 topic_elt['author'] = client.jid.userhost() | 296 topic_elt['author'] = client.jid.userhost() |
296 topic_elt.addElement('title', content = title) | 297 topic_elt.addElement('title', content = title) |
297 yield self._p.sendItem(client, service, node, topic_elt) | 298 await self._p.sendItem(client, service, node, topic_elt) |