plugin XEP-0277: "user" part of author jid is used for author name when later is missing

This commit is contained in:
Goffi 2021-06-06 22:06:28 +02:00
commit 510e3e9bdc

View file

@ -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")