From 510e3e9bdc33f856065b62c6cb0c435f2599d372 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 6 Jun 2021 22:06:28 +0200 Subject: [PATCH] plugin XEP-0277: "user" part of author jid is used for author name when later is missing --- sat/plugins/plugin_xep_0277.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sat/plugins/plugin_xep_0277.py b/sat/plugins/plugin_xep_0277.py index 3017c136..af4eb32e 100644 --- a/sat/plugins/plugin_xep_0277.py +++ b/sat/plugins/plugin_xep_0277.py @@ -448,7 +448,7 @@ class XEP_0277(object): "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 @@ class XEP_0277(object): 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")