changeset 3550:7df12ffa6620

plugin XEP-0277: "user" part of author jid is used for author name when later is missing
author Goffi <goffi@goffi.org>
date Sun, 06 Jun 2021 22:06:28 +0200
parents 3fd60beb9b92
children 0ce37cf3fbf4
files sat/plugins/plugin_xep_0277.py
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0277.py	Sun Jun 06 19:35:19 2021 +0200
+++ b/sat/plugins/plugin_xep_0277.py	Sun Jun 06 22:06:28 2021 +0200
@@ -448,7 +448,7 @@
                     "No name element found in author element of item {}".format(id_)
                 )
             else:
-                microblog_data["author"] = str(name_elt)
+                author = microblog_data["author"] = str(name_elt).strip()
             # uri
             try:
                 uri_elt = next(author_elt.elements(NS_ATOM, "uri"))
@@ -467,6 +467,13 @@
                     microblog_data["author_jid"] = (
                         item_elt.getAttribute("publisher") or ""
                     )
+                if not author and microblog_data["author_jid"]:
+                    # FIXME: temporary workaround for missing author name, would be
+                    #   better to use directly JID's identity (to be done from frontends?)
+                    try:
+                        microblog_data["author"] = jid.JID(microblog_data["author_jid"]).user
+                    except Exception as e:
+                        log.warning(f"No author name found, and can't parse author jid: {e}")
 
                 if not publisher:
                     log.debug("No publisher attribute, we can't verify author jid")