changeset 3724:a0c08fcfe11e

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`
author Goffi <goffi@goffi.org>
date Tue, 25 Jan 2022 17:22:15 +0100
parents 1cdb9d9fad6b
children 9b45f0f168cf
files sat/plugins/plugin_xep_0277.py
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0277.py	Tue Jan 25 17:16:37 2022 +0100
+++ b/sat/plugins/plugin_xep_0277.py	Tue Jan 25 17:22:15 2022 +0100
@@ -77,6 +77,7 @@
 
 class XEP_0277(object):
     namespace = NS_MICROBLOG
+    NS_ATOM = NS_ATOM
 
     def __init__(self, host):
         log.info(_("Microblogging plugin initialization"))
@@ -468,6 +469,7 @@
                 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 @@
 
         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 @@
                     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 @@
                             # 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 @@
 
         ## 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 ##