comparison sat/plugins/plugin_xep_0277.py @ 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 13e7ef106589
children edc79cefe968 30196b9a2b4c
comparison
equal deleted inserted replaced
3549:3fd60beb9b92 3550:7df12ffa6620
446 except StopIteration: 446 except StopIteration:
447 log.warning( 447 log.warning(
448 "No name element found in author element of item {}".format(id_) 448 "No name element found in author element of item {}".format(id_)
449 ) 449 )
450 else: 450 else:
451 microblog_data["author"] = str(name_elt) 451 author = microblog_data["author"] = str(name_elt).strip()
452 # uri 452 # uri
453 try: 453 try:
454 uri_elt = next(author_elt.elements(NS_ATOM, "uri")) 454 uri_elt = next(author_elt.elements(NS_ATOM, "uri"))
455 except StopIteration: 455 except StopIteration:
456 log.debug( 456 log.debug(
465 microblog_data["author_jid"] = uri 465 microblog_data["author_jid"] = uri
466 else: 466 else:
467 microblog_data["author_jid"] = ( 467 microblog_data["author_jid"] = (
468 item_elt.getAttribute("publisher") or "" 468 item_elt.getAttribute("publisher") or ""
469 ) 469 )
470 if not author and microblog_data["author_jid"]:
471 # FIXME: temporary workaround for missing author name, would be
472 # better to use directly JID's identity (to be done from frontends?)
473 try:
474 microblog_data["author"] = jid.JID(microblog_data["author_jid"]).user
475 except Exception as e:
476 log.warning(f"No author name found, and can't parse author jid: {e}")
470 477
471 if not publisher: 478 if not publisher:
472 log.debug("No publisher attribute, we can't verify author jid") 479 log.debug("No publisher attribute, we can't verify author jid")
473 microblog_data["author_jid_verified"] = False 480 microblog_data["author_jid_verified"] = False
474 elif jid.JID(publisher).userhostJID() == jid.JID(uri).userhostJID(): 481 elif jid.JID(publisher).userhostJID() == jid.JID(uri).userhostJID():