plugin misc forums: use rich content in createTopic

This commit is contained in:
Goffi 2021-05-01 18:23:42 +02:00
commit 6456df58fb

View file

@ -272,20 +272,21 @@ class forums(object):
def _createTopic(self, service, node, mb_data, profile_key):
client = self.host.getClient(profile_key)
return self.createTopic(client, jid.JID(service), node, mb_data)
return defer.ensureDeferred(
self.createTopic(client, jid.JID(service), node, mb_data)
)
@defer.inlineCallbacks
def createTopic(self, client, service, node, mb_data):
async def createTopic(self, client, service, node, mb_data):
try:
title = mb_data['title']
if not 'content' in mb_data:
raise KeyError('content')
content = mb_data.pop('content')
except KeyError as e:
raise exceptions.DataError("missing mandatory data: {key}".format(key=e.args[0]))
else:
mb_data["content_rich"] = content
topic_node = FORUM_TOPIC_NODE_TPL.format(node=node, uuid=shortuuid.uuid())
yield self._p.createNode(client, service, topic_node, self._node_options)
self._m.send(client, mb_data, service, topic_node)
await self._p.createNode(client, service, topic_node, self._node_options)
await self._m.send(client, mb_data, service, topic_node)
topic_uri = uri.buildXMPPUri('pubsub',
subtype='microblog',
path=service.full(),
@ -294,4 +295,4 @@ class forums(object):
topic_elt['uri'] = topic_uri
topic_elt['author'] = client.jid.userhost()
topic_elt.addElement('title', content = title)
yield self._p.sendItem(client, service, node, topic_elt)
await self._p.sendItem(client, service, node, topic_elt)