plugin XEP-0277: various fixes + async:

- `NS_ATOM` is now set at class level, so it can be accessed by other plugins
- set `author` to `None` when no `name` element is found
- make `data2entry` a corountine
- fix incorrect use of yield in `trigger.point`
This commit is contained in:
Goffi 2022-01-25 17:22:15 +01:00
commit ab4468a50a

View file

@ -77,6 +77,7 @@ class NodeAccessChangeException(Exception):
class XEP_0277(object):
namespace = NS_MICROBLOG
NS_ATOM = NS_ATOM
def __init__(self, host):
log.info(_("Microblogging plugin initialization"))
@ -468,6 +469,7 @@ class XEP_0277(object):
log.warning(
"No name element found in author element of item {}".format(id_)
)
author = None
else:
author = microblog_data["author"] = str(name_elt).strip()
# uri
@ -541,8 +543,7 @@ class XEP_0277(object):
defer.returnValue(microblog_data)
@defer.inlineCallbacks
def data2entry(self, client, data, item_id, service, node):
async def data2entry(self, client, data, item_id, service, node):
"""Convert a data dict to en entry usable to create an item
@param data: data dict as given by bridge method.
@ -569,7 +570,7 @@ class XEP_0277(object):
elem = entry_elt.addElement(elem_name)
if type_:
if type_ == "_rich": # convert input from current syntax to XHTML
xml_content = yield synt.convert(
xml_content = await synt.convert(
data[attr], synt.getCurrentSyntax(client.profile), "XHTML"
)
if "{}_xhtml".format(elem_name) in data:
@ -601,7 +602,7 @@ class XEP_0277(object):
# there is raw text content, which is mandatory
# so we create one from xhtml content
elem_txt = entry_elt.addElement(elem_name)
text_content = yield self.host.plugins[
text_content = await self.host.plugins[
"TEXT_SYNTAXES"
].convert(
xml_content,
@ -689,11 +690,11 @@ class XEP_0277(object):
## the trigger ##
# if other plugins have things to add or change
yield self.host.trigger.point(
self.host.trigger.point(
"XEP-0277_data2entry", client, data, entry_elt, item_elt
)
defer.returnValue(item_elt)
return item_elt
## publish/preview ##